Last active
October 1, 2023 01:38
-
-
Save chodorowicz/65f3af3a3ad00f08afbc7eea3ffeee1e to your computer and use it in GitHub Desktop.
get depth level of current term on taxonomy archive page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://stackoverflow.com/questions/22307013/wordpress-get-current-level-of-taxonomy-in-an-archive-page | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment