is_taxonomy_hierarchical( string $taxonomy ): bool
- Since
- 2.3.0
- Source
wp-includes/taxonomy.php:399
Description
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 https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags article in the Theme Developer Handbook.
Compatibility
- WordPress
- since 2.3.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$taxonomystring- Name of taxonomy object.
Return value
bool- Whether the taxonomy is hierarchical.
Performance profile
How much work a call to is_taxonomy_hierarchical() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 6–11
- Plugin surface
- None
- Called by
- 28
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 12.
Nothing here hands control to plugin code.
28 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost is_taxonomy_hierarchical() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!taxonomy_exists() | 6 | taxonomy_exists() |
taxonomy_exists() | 11 | taxonomy_exists(), get_taxonomy() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 12 instructions, 6–11 executed per call, 1 branch. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 2
- taxonomy_exists()Determines whether the taxonomy name exists.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
Used by · 28
- WP_REST_Menus_Controller::create_item()Creates a single term in a taxonomy.
- WP_REST_Menus_Controller::update_item()Updates a single term from a taxonomy.
- WP_REST_Posts_Controller::get_available_actions()Gets the link relations available for the post and current user.
- WP_REST_Terms_Controller::create_item()Creates a single term in a taxonomy.
- WP_REST_Terms_Controller::create_item_permissions_check()Checks if a request has access to create a term.
- WP_REST_Terms_Controller::update_item()Updates a single term from a taxonomy.
- WP_Tax_Query::clean_query()Validates a single query.
- WP_Tax_Query::transform_query()Transforms a single query, from one field to another.
- WP_Term_Query::get_terms()Retrieves the query results.
- WP_Terms_List_Table::display_rows_or_placeholder()
- WP_Terms_List_Table::get_sortable_columns()
- WP_Terms_List_Table::prepare_items()
Show all 28
- _get_term_hierarchy()Retrieves children of taxonomy as term IDs.
- _pad_term_counts()Adds count of children to parent count.
- _wp_menu_item_classes_by_context()Adds the class property classes for the current context, if applicable.
- block_core_breadcrumbs_get_term_ancestors_items()Generates breadcrumb items for hierarchical term ancestors.
- bulk_edit_posts()Processes the post data for the bulk editing of posts.
- clean_taxonomy_cache()Cleans the caches for a taxonomy.
- get_ancestors()Gets an array of ancestor IDs for a given object.
- register_and_do_post_meta_boxes()Registers the default post meta boxes, and runs the `do_meta_boxes` actions.
- render_block_core_term_template()Renders the `core/term-template` block on the server.
- wp_ajax_add_tag()Handles adding a tag via AJAX.
- wp_delete_term()Removes a term from the database.
- wp_insert_term()Adds a new term to the database.
- wp_nav_menu_item_taxonomy_meta_box()Displays a meta box for a taxonomy menu item.
- wp_set_post_terms()Sets the terms for a post.
- wp_unique_term_slug()Makes term slug unique, if it isn't already.
- wp_xmlrpc_server::_insert_post()Helper method for wp_newPost() and wp_editPost(), containing shared logic.
Source code
function is_taxonomy_hierarchical( $taxonomy ) { if ( ! taxonomy_exists( $taxonomy ) ) { return false; } $taxonomy = get_taxonomy( $taxonomy ); return $taxonomy->hierarchical;}Changelog
Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/taxonomy.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.