I'm trying to put in a conditional in my archive.php
that sorts our whether the taxonomy is hierarchical or not. This is what I have so far but it doesn't work.
<?php if ( is_taxonomy_hierarchical() ) { ?>
I am a hierarchical tax
<?php } else { ?>
I am NOT a hierarchical tax
<?php } ?>
I'm trying to put in a conditional in my archive.php
that sorts our whether the taxonomy is hierarchical or not. This is what I have so far but it doesn't work.
<?php if ( is_taxonomy_hierarchical() ) { ?>
I am a hierarchical tax
<?php } else { ?>
I am NOT a hierarchical tax
<?php } ?>
Share
Improve this question
asked Feb 2, 2019 at 3:38
PetePete
1,0582 gold badges14 silver badges40 bronze badges
1 Answer
Reset to default 2Look at the docs (please read the docs) for is_taxonomy_hierarchical()
. You need to tell it which taxonomy you're checking:
if ( is_taxonomy_hierarchical( 'my_taxonomy_name' ) ) {
}
If you're template isn't specific to a taxonomy, and you need to know which taxonomy you're viewing, use get_queried_object()
to figure it out (you were already told how to do this, by the way):
if ( is_tax() ) {
$taxonomy = get_queried_object()->taxonomy;
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
} else {
}
}