taxonomy_exists()判断一个分类法是否存在

目录

描述

This Conditional Tag checks if the taxonomy name exists by passing a taxonomy name as an argument to it. This is a boolean function uses a global $wp_taxonomies variable for checking if taxonomy name existence, meaning it returns either TRUE if the taxonomy name exist or FALSE if it doesn't exist.

taxonomy_exists() 描述

用法

<?php taxonomy_exists($taxonomy); ?>

taxonomy_exists() 用法

参数

$taxonomy

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

默认值: None

taxonomy_exists() 参数

返回值

(boolean) 

True on success, false on failure.

taxonomy_exists() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
$taxonomy_exist = taxonomy_exists('category');
//returns true

$taxonomy_exist = taxonomy_exists('post_tag');
//returns true

$taxonomy_exist = taxonomy_exists('link_category');
//returns true

$taxonomy_exist = taxonomy_exists('my_taxonomy');
//returns false if global $wp_taxonomies['my_taxonomy'] is not set

taxonomy_exists() 示例

注意

历史

添加于 版本: 3.0

taxonomy_exists() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Checks that the taxonomy name exists.
 *
 * Formerly is_taxonomy(), introduced in 2.3.0.
 *
 * @since 3.0.0
 *
 * @global array $wp_taxonomies The registered taxonomies.
 *
 * @param string $taxonomy Name of taxonomy object.
 * @return bool Whether the taxonomy exists.
 */
function taxonomy_exists( $taxonomy ) {
	global $wp_taxonomies;

	return isset( $wp_taxonomies[$taxonomy] );
}

taxonomy_exists() 源文件

相关