Created
May 22, 2012 15:42
-
-
Save claytantor/2769834 to your computer and use it in GitHub Desktop.
Wordpress Find Category By Term Name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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