Last active
June 6, 2016 21:44
-
-
Save kodie/de1f518fd95582facc24 to your computer and use it in GitHub Desktop.
Find out if post has a term that is the descendant of another term.
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
function has_term_descendant($parent_term, $taxonomy, $post_id = null) { | |
if (empty($post_id)) { $post_id = get_the_ID(); } | |
$terms = get_the_terms($post_id, $taxonomy); | |
if (!empty($terms)) { | |
foreach ($terms as $term) { | |
if (term_is_ancestor_of($parent_term, $term, $taxonomy)) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment