Skip to content

Instantly share code, notes, and snippets.

@kodie
Last active June 6, 2016 21:44
Show Gist options
  • Save kodie/de1f518fd95582facc24 to your computer and use it in GitHub Desktop.
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.
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