You can use get_ancestors()
to get an array of parents, which you can then count.
$term_id = 42;
$ancestors = get_ancestors( $term_id, 'category' );
if( ! empty( $ancestors ) ){
echo count( $ancestors );
}
You can use get_ancestors()
to get an array of parents, which you can then count.
$term_id = 42;
$ancestors = get_ancestors( $term_id, 'category' );
if( ! empty( $ancestors ) ){
echo count( $ancestors );
}