get_taxonomy()通过分类法名称获取一个分类法的信息

目录

描述

Get the object containing a taxonomy's settings (metadata).

Note that it does NOT return the list of terms associated with the taxonomy. To do this, you should use wp_list_categories()

get_taxonomy() 描述

用法

<?php get_taxonomy$taxonomy ?>

get_taxonomy() 用法

参数

$taxonomy

(string) (必填) The name of the taxonomy

默认值: None

get_taxonomy() 参数

返回值

(object) 

Returns an object containing the taxonomy metadata on success.

Returns false if the taxonomy does not exist.

get_taxonomy() 返回值

示例

For example for a custom taxonomy named "features" associated with a custom post type named "rentals".

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
 $rental_features = get_taxonomy( 'features' );
 print_r( $rental_features );
 
 stdClass Object ( 
 [hierarchical] => 
 [update_count_callback] => 
 [rewrite] => 
     Array ( [slug] => features [with_front] => 1 ) 
 [query_var] => features 
 [public] => 1 
 [show_ui] => 1 
 [show_tagcloud] => 1 
 [_builtin] => 
 [labels] => 
   stdClass Object ( 
       [name] => Features 
       [singular_name] => Feature 
       [search_items] => Search Features 
       [popular_items] => Popular Features 
       [all_items] => All Features 
       [parent_item] => Parent Feature 
       [parent_item_colon] => Parent Feature: 
       [edit_item] => Edit Feature 
       [update_item] => Update Feature 
       [add_new_item] => Add New Feature 
       [new_item_name] => New Feature Name 
       [separate_items_with_commas] => Separate Features with commas 
       [add_or_remove_items] => Add or remove Features 
       [choose_from_most_used] => Choose from the most used Features 
    ) 
 [show_in_nav_menus] => 1 
 [label] => Features 
 [singular_label] => Feature 
 [cap] => 
   stdClass Object ( 
       [manage_terms] => manage_categories 
       [edit_terms] => manage_categories 
       [delete_terms] => manage_categories 
       [assign_terms] => edit_posts 
   ) 
 [name] => features 
 [object_type] => 
   Array ( [0] => rentals [1] => rentals ) 
)

get_taxonomy() 示例

注意

  • 使用到 global: $wp_taxonomies (array)

get_taxonomy() 注意

历史

  • 添加于 版本: 2.3.0

get_taxonomy() 历史

源文件

get_taxonomy() 函数的代码位于 wp-includes/taxonomy.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieves the taxonomy object of $taxonomy.
 *
 * The get_taxonomy function will first check that the parameter string given
 * is a taxonomy object and if it is, it will return it.
 *
 * @since 2.3.0
 *
 * @global array $wp_taxonomies The registered taxonomies.
 *
 * @param string $taxonomy Name of taxonomy object to return.
 * @return object|false The Taxonomy Object or false if $taxonomy doesn't exist.
 */
function get_taxonomy( $taxonomy ) {
	global $wp_taxonomies;

	if ( ! taxonomy_exists( $taxonomy ) )
		return false;

	return $wp_taxonomies[$taxonomy];
}

get_taxonomy() 源文件