/ Published in: PHP
Expand |
Embed | Plain Text
<?php function has_term($term_name, $taxonomy_name) { $terms = get_terms($taxonomy_name, 'fields=names'); if ($terms[$i] == $term_name) { return true; } } return false; } ?>
Comments
Subscribe to comments
You need to login to post a comment.

Ok, you created a Custom Post Type and some Custom Taxonomies for it. Now you want to check wether your post has a term (aka category) from the new taxonomy. There's no built-in function for this, or at least none that I know of (but I may be wrong).
Anyway, this simple function requires 2 parameters: 1) the term name, 2) the taxonomy name. It returns a boolean. Just paste it in your functions.php file and you're good to go.
Oh, I almost forgot: term names are case-sensitive, so type carefully.