Skip to content

Instantly share code, notes, and snippets.

@claytantor
Created May 22, 2012 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claytantor/2769834 to your computer and use it in GitHub Desktop.
Save claytantor/2769834 to your computer and use it in GitHub Desktop.
Wordpress Find Category By Term Name
/*
really cant believe this isn't native
*/
function get_category_by_term_name($categoryName=null){
//if you get this via a tag it will have been html encoded
$string = preg_replace('/&(?!amp;)/', '&', $categoryName);
$string = preg_replace('/#038;/', '', $string);
$term = get_term_by('name',$string,'category');
return get_category($term->term_id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment