Description
Get a list of registered taxonomy
objects.
<?php get_taxonomies( $args, $output, $operator ) ?>
$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
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] )
The call to get_taxonomies
returns the registered taxonomies.
<?php
$taxonomies=get_taxonomies(); ?>
<?php
$taxonomies=get_taxonomies('','names');
foreach
($taxonomies as $taxonomy ) {
echo '<p>'. $taxonomy. '</p>';
}
?>
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>';
}
}
?>
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>';
}
}
?>
No comments:
Post a Comment