get_taxonomies()WP 3.0.0

Gets the list of registered taxonomies. You can restrict the list to the desired parameters.

Use get_object_taxonomies() to get taxonomies of specific post_types only.

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

No Hooks.

Return

String[]|WP_Taxonomy[].

  • Array of names - when $output parameter is 'names'.
  • Array of WP_Taxonomy objects - when parameter $output is 'objects'.

Names Return examples:

Array (
	[special_taxonomy] => special_taxonomy,
	[custom_taxonomy] => custom_taxonomy
)

Objects Return examples:

Array
(
	[category] => WP_Taxonomy Object
		(
			[name] => category
			[label] => Categories
			[labels] => stdClass Object
				(
					[name] => Categories
					[singular_name] => Category
					[search_items] => Search Categories
					[popular_items] =>
					[all_items] => All Categories
					[parent_item] => Parent Category
					[parent_item_colon] => Parent Category:
					[name_field_description] => The name is how it appears on your site.
					[slug_field_description] => The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.
					[parent_field_description] => Assign a parent term to create a hierarchy. The term Jazz, for example, would be the parent of Bebop and Big Band.
					[desc_field_description] => The description is not prominent by default; however, some themes may show it.
					[edit_item] => Edit Category
					[view_item] => View Category
					[update_item] => Update Category
					[add_new_item] => Add New Category
					[new_item_name] => New Category Name
					[separate_items_with_commas] =>
					[add_or_remove_items] =>
					[choose_from_most_used] =>
					[not_found] => No categories found.
					[no_terms] => No categories
					[filter_by_item] => Filter by category
					[items_list_navigation] => Categories list navigation
					[items_list] => Categories list
					[most_used] => Most Used
					[back_to_items] => ← Go to Categories
					[item_link] => Category Link
					[item_link_description] => A link to a category.
					[menu_name] => Categories
					[name_admin_bar] => category
				)

			[description] =>
			[public] => 1
			[publicly_queryable] => 1
			[hierarchical] => 1
			[show_ui] => 1
			[show_in_menu] => 1
			[show_in_nav_menus] => 1
			[show_tagcloud] => 1
			[show_in_quick_edit] => 1
			[show_admin_column] => 1
			[meta_box_cb] => post_categories_meta_box
			[meta_box_sanitize_cb] => taxonomy_meta_box_sanitize_cb_checkboxes
			[object_type] => Array
				(
					[0] => post
				)

			[cap] => stdClass Object
				(
					[manage_terms] => manage_categories
					[edit_terms] => edit_categories
					[delete_terms] => delete_categories
					[assign_terms] => assign_categories
				)

			[rewrite] => Array
				(
					[with_front] =>
					[hierarchical] => 1
					[ep_mask] => 512
					[slug] => cat
				)

			[query_var] => category_name
			[update_count_callback] =>
			[show_in_rest] => 1
			[rest_base] => categories
			[rest_namespace] => wp/v2
			[rest_controller_class] => WP_REST_Terms_Controller
			[rest_controller] =>
			[default_term] =>
			[sort] =>
			[args] =>
			[_builtin] => 1
		)

	[post_tag] => WP_Taxonomy Object ()
	...
}

Usage

get_taxonomies( $args, $output, $operator );
$args(array)

An array of key => value arguments to match against the taxonomy objects. I.e. by specifying the necessary parameters, we can get data only about the taxonomies we need.

Parameters that can be specified in the array:

  • name - taxonomy name.
  • object_type - (array) to which types of posts the taxonomy is attached.
  • hierarchical - true - will show only tree-like taxonomies.
  • show_in_nav_menus
  • cap - (object) capabilities.
  • label - title (taxonomy name).
  • labels - (object) taxonomy titles (different names).
  • singular_label
  • show_ui
  • show_tagcloud
  • public - true - get public taxonomies only.
  • update_count_callback.
  • rewrite
  • query_var
  • manage_cap
  • edit_cap
  • delete_cap
  • assign_cap
  • _builtin - false - exclude built-in taxonomies (for example, category).

See complete list and what each parameter means in register_taxonomy() function description.

Default: empty array

$output(string)

The view in which the result of the function will be obtained:

  • names - Get only names of registered taxonomies (default).
  • objects` - Get an array of objects with full information about the taxonomies.

Default: 'names'

$operator(string)

The logical operator that defines how to process multiple values of $args parameter. Accepts:

  • or - selects taxonomies where any of specified $args element is match.
  • and - selects taxonomies where all elements from $args is match.

Default: 'and'

Examples

0

#1 Let's display all registered taxonomies:

Get an array of names of all registered taxonomies.

$taxonomies = get_taxonomies();

foreach( $taxonomies as $taxonomy ) {
	echo '<p>'. $taxonomy. '</p>';
}
0

#2 Get only public taxonomies

Let's display the list of public ('public' => true) taxonomies that are not WP internal ones ('_builtin' => false):

$args = [
	'public'   => true,
	'_builtin' => false
];

$output = 'names'; // or objects
$operator = 'and'; // 'and' or 'or'

$taxonomies = get_taxonomies( $args, $output, $operator );

if( $taxonomies ){
	foreach( $taxonomies as $taxonomy ){
		echo '<p>'. $taxonomy. '</p>';
	}
}
0

#3 Let's get the 'genre' taxonomy

Let's get a taxonomy called 'genre' ('name' => 'genre') and display it's plural name ($taxonomy->labels->name):

$args = [
  'name' => 'genre'
];

$output = 'objects'; // or objects
$taxonomies = get_taxonomies( $args, $output );

if( $taxonomies ) {
	foreach ( $taxonomies as $taxonomy ) {
		echo '<p>' . $taxonomy->labels->name . '</p>';
	}
}
0

#4 Get taxonomies of post_type

If you query for taxonomies with a certain post type, for example, as shown below, only the taxonomies associated with that post type will be shown. If a taxonomy is associated with more than one post type, it will not be shown.

$args = [
	'object_type' => [ 'post' ]
];

$taxonomies = get_taxonomies( $args );

print_r( $taxonomies );

/*
Array
(
	[category] => category
	[post_tag] => post_tag
	[post_format] => post_format
)
*/

The alternative is to use get_object_taxonomies().

0

#5 Get all the taxonomies used in the REST API

$rest_taxes = get_taxonomies( [ 'show_in_rest' => true ], 'names' );

print_r( $rest_taxes );

/*
Array
(
	[category] => category
	[post_tag] => post_tag
	[nav_menu] => nav_menu
	[note_tag] => note_tag
)
*/

Notes

  • Global. WP_Taxonomy[]. $wp_taxonomies The registered taxonomies.

Changelog

Since 3.0.0 Introduced.

get_taxonomies() code WP 6.4.3

function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) {
	global $wp_taxonomies;

	$field = ( 'names' === $output ) ? 'name' : false;

	return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field );
}