Skip to content

Instantly share code, notes, and snippets.

@chodorowicz
Last active October 1, 2023 01:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chodorowicz/65f3af3a3ad00f08afbc7eea3ffeee1e to your computer and use it in GitHub Desktop.
Save chodorowicz/65f3af3a3ad00f08afbc7eea3ffeee1e to your computer and use it in GitHub Desktop.
get depth level of current term on taxonomy archive page
<?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