is_taxonomy_hierarchical()WP 2.3.0

Checks if the specified taxonomy is hierarchical. Conditional tag.

1 time — 0.000011 sec (very fast) | 50000 times — 0.02 sec (speed of light) | PHP 7.0.8, WP 4.6.1

No Hooks.

Returns

true|false. Boolean. true if the taxonomy is hierarchical. false if it is normal or the taxonomy does not exist.

Usage

if( is_taxonomy_hierarchical( $taxonomy ) ){
	// do something
}
$taxonomy(string) (required)
The name of the taxonomy to check for hierarchical nature.

Examples

2

#1 Check the custom taxonomy for tree-like structure:

if( is_taxonomy_hierarchical( 'tax_name' ) ){
	// tree
}
else {
	// not a tree
}
0

#2 Check if the taxonomy is tree-like

Let's check the taxonomies post_tag and category whether it hierarchical:

is_taxonomy_hierarchical( 'category' );
// returns: true 

is_taxonomy_hierarchical( 'post_tag' );
// returns: false

Changelog

Since 2.3.0 Introduced.

is_taxonomy_hierarchical() code WP 6.9.1

function is_taxonomy_hierarchical( $taxonomy ) {
	if ( ! taxonomy_exists( $taxonomy ) ) {
		return false;
	}

	$taxonomy = get_taxonomy( $taxonomy );
	return $taxonomy->hierarchical;
}