I cannot completely answer your question, but perhaps this will help.
If you have the term slug, you can retrieve the term info like this:
$term = get_term_by('slug', 'sold', 'home-status');
if ( $term->parent == 0 ) {
// This is a top level
} else {
// This is a child
}
where the field to compare is ‘slug’, the slug is ‘sold’, and the taxonomy is ‘home-status’.
You can also use the term id or name by supplying the proper field value.
Thread Starter
gleenk
(@gleenk)
Hi, no this is not my problem. I need to check terms dynamically. I solved in this way.
Into functions.php:
function get_top_parent_terms( $tassonomia, $termine ){
$topTerms = get_terms( $tassonomia, array('parent' => 0) );
$termini = array();
if ( $topTerms ) :
foreach ( $topTerms as $typeTerm ) :
$termini[] = $typeTerm->term_id;
endforeach;
endif;
return in_array( $termine->term_id, $termini);
}
Into a taxonomy-name.php:
$term = $wp_query->queried_object;
if ( !get_top_parent_terms ( 'categorie-servizi', $term ) ) :
And this works. Hope that helps