WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/get taxonomies

Contents

Description

Get a list of registered taxonomy objects.

Usage

 <?php get_taxonomies$args$output$operator ?> 

Parameters

$args
(array) (optional) An array of key -> value arguments to match against the taxonomies. Only taxonomies having attributes that match all arguments are returned.
Default: None
  • name
  • object_type (array)
  • label
  • singular_label
  • show_ui
  • show_tagcloud
  • public
  • update_count_callback
  • rewrite
  • query_var
  • manage_cap
  • edit_cap
  • delete_cap
  • assign_cap
  • _builtin
$output
(string) (optional) The type of output to return, either taxonomy 'names' or 'objects'.
Default: 'names'
$operator
(string) (optional) Operator (and/or) to use with multiple $args.
Default: and

Return Value

array 
A list of taxonomy names or objects. If returning names, you will get an array of the taxonomy names such as
Array ( [special_taxonomy] => special_taxonomy [custom_taxonomy] => custom_taxonomy )

If returning objects, you will get an array of objects such as:

Array ( [special_taxonomy] => stdClass Object  [custom_taxonomy] => stdClass Object  )

wherein each object will contain the following fields:

stdClass Object ( 
[hierarchical] => 
[update_count_callback] =>  
[rewrite] => 
[query_var] => 
[public] => 
[show_ui] => 
[show_tagcloud] => 
[_builtin] => 
[labels] => stdClass Object ( 
	[name] =>  
	[singular_name] =>
	[search_items] => 
	[popular_items] => 
	[all_items] => 
	[parent_item] => 
	[parent_item_colon] =>  
	[edit_item] => 
	[view_item] =>  
	[update_item] => 
	[add_new_item] => 
	[new_item_name] => 
	[separate_items_with_commas] => 
	[add_or_remove_items] => 
	[choose_from_most_used] => 
	[menu_name] =>  
	[name_admin_bar] =>  ) 
[show_in_nav_menus] => 
[cap] => stdClass Object ( 
	[manage_terms] =>  
	[edit_terms] =>  
	[delete_terms] =>  
	[assign_terms] =>  ) 
[name] =>  
[object_type] => Array () 
[label]  )

Examples

Default Usage

The call to get_taxonomies returns the registered taxonomies.

<?php $taxonomies=get_taxonomies(); ?>

Output a list all registered taxonomies

<?php 
$taxonomies=get_taxonomies('','names'); 
foreach ($taxonomies as $taxonomy ) {
  echo '<p>'. $taxonomy. '</p>';
}
?>

Output a list of all public custom taxonomies

This return all custom (not builtin) taxonomies.

<?php 
$args = array(
  '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>';
  }
}
?>

Output a named taxonomy

This example uses the 'object' output to retrieve and display the taxonomy called 'genre':

<?php 
$args=array(
  'name' => 'genre'
);
$output = 'objects'; // or objects
$taxonomies=get_taxonomies($args,$output); 
if  ($taxonomies) {
  foreach ($taxonomies  as $taxonomy ) {
    echo '<p>' . $taxonomy->name . '</p>';
  }
}  
?>

Source File

get_taxonomies() is located in wp-includes/taxonomy.php.

Change Log

  • Since: 3.0.0

Related

See also index of Function Reference and index of Template Tags.