get_taxonomies() - WordPress 函数参考中文文档

返回介绍

get_taxonomies()

发布于 2017-09-11 字数5183 浏览 1032 评论 0

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

Retrieves a list of registered taxonomy names or objects.


描述


参数

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

更新日志

Version 描述
3.0.0 Introduced.

相关函数

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>';
    	}
    }  
    ?>
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!