返回介绍

get_taxonomies()

发布于 2017-09-11 00:18:05 字数 5181 浏览 1726 评论 0 收藏 0

get_taxonomies( array $args = array(),  string $output = 'names',  string $operator = 'and' )

Retrieves a list of registered taxonomy names or objects.


description


参数

$args

(array) (Optional) An array of key => value arguments to match against the taxonomy objects.

Default value: array()

$output

(string) (Optional) The type of output to return in the array. Accepts either taxonomy 'names' or 'objects'.

Default value: 'names'

$operator

(string) (Optional) The logical operation to perform. Accepts 'and' or 'or'. 'or' means only one element from the array needs to match; 'and' means all elements must match.

Default value: 'and'


返回值

(array) A list of taxonomy names or objects.


源代码

File: wp-includes/taxonomy.php

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);
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-includes/functions.php: wp_filter_object_list()

Used By

  • wp-includes/rest-api.php: create_initial_rest_routes()
  • wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::get_item_schema()
  • wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php: WP_REST_Taxonomies_Controller::get_items_permissions_check()
  • wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php: WP_REST_Taxonomies_Controller::get_items()
  • wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::search_available_items_query()
  • wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::available_item_types()
  • wp-admin/includes/export.php: export_wp()
  • wp-admin/includes/misc.php: set_screen_options()
  • wp-admin/includes/ajax-actions.php: wp_ajax_menu_get_metabox()
  • wp-admin/includes/nav-menu.php: wp_nav_menu_taxonomy_meta_boxes()
  • wp-includes/class-wp.php: WP::parse_request()
  • wp-includes/class-wp-query.php: WP_Query::parse_tax_query()
  • wp-includes/widgets/class-wp-widget-tag-cloud.php: WP_Widget_Tag_Cloud::form()
  • wp-includes/post-template.php: get_post_class()
  • wp-includes/media.php: get_taxonomies_for_attachments()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getTaxonomies()
  • Show 11 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by hearvox

    Display a list all registered taxonomies:

    
    <?php
    $taxonomies = get_taxonomies();
    if ( ! empty( $taxonomies ) ) : ?>
    	<ul>
    		<?php
    		foreach ( $taxonomies as $taxonomy ) {
    		    echo '<li>' . $taxonomy . '</li>';
    		}
    		?>
    	</ul>
    <?php endif; ?>
    
  2. Display a list of only public custom taxonomies — will not list include WordPress built-in taxonomies (e.g., categories and tags):

    
    <?php 
    $args = array(
      'public'   => true,
      '_builtin' => false
      
    ); 
    $output = 'names'; // or objects
    $operator = 'and'; // 'and' or 'or'
    $taxonomies = get_taxonomies( $args, $output, $operator ); 
    if ( $taxonomies ) {
    	echo '<ul>';
    	foreach ( $taxonomies  as $taxonomy ) {
    		echo '<li>' . $taxonomy . '</li>';
    	}
    	echo '</ul>';	
    }
    ?>
    

    Display the plural name of a specific taxonomy (and setting the output to be 'object' rather than the default 'array‘):

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文