kodie
2/1/2016 - 4:28 PM

Find out if post has a term that is the descendant of another term.

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;
}