delarge
3/25/2019 - 10:39 PM

taxonomy test for child parent

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); // get current term
$parent = get_term($term->parent, get_query_var('taxonomy') ); // get parent term
$children = get_term_children($term->term_id, get_query_var('taxonomy')); // get children

if(($parent->term_id!="" && sizeof($children)>0)) {

	// has parent and child
  echo "has parent and child";

}elseif(($parent->term_id!="") && (sizeof($children)==0)) {

	// has parent, no child
  echo "has parent, no child";

}elseif(($parent->term_id=="") && (sizeof($children)>0)) {

	// no parent, has child
  //echo "no parent, has child";

}