is_taxonomy_hierarchical()WP 2.3.0

Whether the taxonomy object is hierarchical.

Checks to make sure that the taxonomy is an object first. Then Gets the object, and finally returns the hierarchical value in the object.

A false return value might also mean that the taxonomy does not exist.

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

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.

Return

true|false. Whether the taxonomy is hierarchical.

Usage

is_taxonomy_hierarchical( $taxonomy );
$taxonomy(string) (required)
Name of taxonomy object.

Examples

0

#1 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
0

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

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

Changelog

Since 2.3.0 Introduced.

is_taxonomy_hierarchical() code WP 6.1.1

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

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