get_taxonomy( string $taxonomy ): WP_Taxonomy|false
- Since
- 2.3.0
- Source
wp-includes/taxonomy.php:350
Looks up a registered taxonomy by its name and returns the matching WP_Taxonomy object, or false if the name isn't registered. Useful when you already have a taxonomy slug (like 'category' or a custom one) and need its labels, capabilities, or object_type without querying terms. Pair it with taxonomy_exists() if you only need a yes/no check.
Description
The get_taxonomy function will first check that the parameter string given is a taxonomy object and if it is, it will return it.
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 to return.
Return value
WP_Taxonomy|false- The taxonomy object or false if $taxonomy doesn't exist.
Code examples
Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.
Display the label and post types for a built-in taxonomy
Categories and tags are already registered on every WordPress install, so this runs against the built-in 'category' taxonomy.
$taxonomy = get_taxonomy( 'category' );
if ( $taxonomy ) {
printf(
'Label: %s | Object types: %s',
esc_html( $taxonomy->label ),
esc_html( implode( ', ', $taxonomy->object_type ) )
);
} else {
echo 'Taxonomy not found.';
}Check whether a custom taxonomy is registered before reading its capabilities
Register a custom 'genre' taxonomy for posts, then confirm it exists and inspect its manage_terms capability.
$genre_taxonomy = get_taxonomy( 'genre' );
if ( $genre_taxonomy ) {
printf(
'Hierarchical: %s | manage_terms cap: %s',
$genre_taxonomy->hierarchical ? 'yes' : 'no',
esc_html( $genre_taxonomy->cap->manage_terms )
);
} else {
echo 'Genre taxonomy is not registered.';
}The taxonomy has to be registered on every request via register_taxonomy() before get_taxonomy() can find it.
Common problems and fixes · 3
- Why does get_taxonomy() return false for a taxonomy I know I registered?
- How do I get every registered taxonomy instead of just one?
- What's on the WP_Taxonomy object get_taxonomy() returns?
Why does get_taxonomy() return false for a taxonomy I know I registered?
How do I get every registered taxonomy instead of just one?
What's on the WP_Taxonomy object get_taxonomy() returns?
Alternatives and related functions
get_taxonomies- When you need a list of multiple registered taxonomies (optionally filtered by args) instead of a single one by name.
taxonomy_exists- When all you need is a true/false check and don't need the full WP_Taxonomy object.
register_taxonomy- When the taxonomy doesn't exist yet and you need to create it before get_taxonomy() can find it.
get_taxonomy_labels- When you specifically need the labels object for a taxonomy rather than the whole WP_Taxonomy instance.
Performance profile
How much work a call to get_taxonomy() 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
- 7–8
- Plugin surface
- None
- Called by
- 50
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 9.
Nothing here hands control to plugin code.
50 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_taxonomy() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7–8 | taxonomy_exists() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 9 instructions, 7–8 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 · 1
- taxonomy_exists()Determines whether the taxonomy name exists.
Used by · 50
- WP_Customize_Nav_Menu_Item_Setting::get_type_label()Get type label.
- WP_Customize_Nav_Menus::load_available_items_query()Performs the post_type and taxonomy queries for loading available menu items.
- WP_Customize_Nav_Menus::search_available_items_query()Performs post queries for available-item searching.
- WP_Links_List_Table::extra_tablenav()
- WP_Media_List_Table::column_default()Handles output for the default column.
- WP_Media_List_Table::get_columns()
- WP_Posts_List_Table::categories_dropdown()Displays a categories drop-down for filtering on the Posts list table.
- WP_Posts_List_Table::column_default()Handles the default column output.
- WP_Posts_List_Table::get_columns()
- WP_Posts_List_Table::inline_edit()Outputs the hidden row displayed when inline editing
- WP_REST_Menu_Items_Controller::prepare_item_for_database()Prepares a single nav menu item for create or update.
- WP_REST_Taxonomies_Controller::get_item()Retrieves a specific taxonomy.
Show all 50
- WP_REST_Taxonomies_Controller::get_item_permissions_check()Checks if a given request has access to a taxonomy.
- WP_REST_Terms_Controller::__construct()Constructor.
- WP_REST_Terms_Controller::check_is_taxonomy_allowed()Checks that the taxonomy is valid.
- WP_REST_Terms_Controller::create_item_permissions_check()Checks if a request has access to create a term.
- WP_REST_Terms_Controller::get_collection_params()Retrieves the query params for collections.
- WP_REST_Terms_Controller::get_item_schema()Retrieves the term's schema, conforming to JSON Schema.
- WP_REST_Terms_Controller::get_items()Retrieves terms associated with a taxonomy.
- WP_REST_Terms_Controller::get_items_permissions_check()Checks if a request has access to read terms in the specified taxonomy.
- WP_REST_Terms_Controller::prepare_links()Prepares links for the request.
- WP_Terms_List_Table::__construct()Constructor.
- WP_Terms_List_Table::ajax_user_can()
- WP_Terms_List_Table::column_posts()
- WP_Terms_List_Table::get_bulk_actions()
- WP_Terms_List_Table::inline_edit()Outputs the hidden row displayed when inline editing
- WP_Terms_List_Table::no_items()
- WP_Widget_Tag_Cloud::widget()Outputs the content for the current Tag Cloud widget instance.
- _pad_term_counts()Adds count of children to parent count.
- _post_format_request()Filters the request to allow for the format prefix.
- _wp_ajax_add_hierarchical_term()Handles adding a hierarchical term via AJAX.
- _wp_build_title_and_description_for_taxonomy_block_template()Builds the title and description of a taxonomy-specific template based on the underlying entity referenced.
- _wp_translate_postdata()Renames `$_POST` data from form names to DB post columns.
- bulk_edit_posts()Processes the post data for the bulk editing of posts.
- edit_post()Updates an existing post with values provided in `$_POST`.
- edit_term_link()Displays or retrieves the edit term link with formatting.
- feed_links_extra()Displays the links to the extra feeds such as category feeds.
- get_attachment_fields_to_edit()Retrieves the attachment fields to edit form fields.
- get_compat_media_markup()
- get_edit_term_link()Retrieves the URL for editing a given term.
- get_inline_data()Adds hidden fields with the data for use in the inline editor for posts and pages.
- get_term_feed_link()Retrieves the feed link for a term.
- get_term_link()Generates a permalink for a taxonomy term archive.
- get_the_archive_title()Retrieves the archive title based on the queried object.
- get_the_taxonomies()Retrieves all taxonomies associated with a post.
- is_taxonomy_hierarchical()Determines whether the taxonomy object is hierarchical.
- is_taxonomy_viewable()Determines whether a taxonomy is considered "viewable".
- map_meta_cap()Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked.
- post_categories_meta_box()Displays post categories form fields.
- post_tags_meta_box()Displays post tags form fields.
Source code
function get_taxonomy( $taxonomy ) { global $wp_taxonomies; if ( ! taxonomy_exists( $taxonomy ) ) { return false; } return $wp_taxonomies[ $taxonomy ];}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 6.7.7 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.