get_tax_level category, tax level wordpress

01 Jun 2020
0 Comments
                
                    
function get_tax_level($id, $tax){
    $ancestors = get_ancestors($id, $tax);
    return count($ancestors)+1;
}

$current_term_level = get_tax_level(get_queried_object()->term_id, get_queried_object()->taxonomy);

if ($current_term_level == 1) {
    // show first drop-down
} else if ($current_term_level == 2) {
    // show second drop-down
} else {
    // show third drop-down
}
                
            

Leave a Reply

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.