register_taxonomy_for_object_type()为一个文章类型添加分类法

目录

描述

Add a registered Taxonomy to a registered Post Type.

register_taxonomy_for_object_type() 描述

用法

 <?php register_taxonomy_for_object_type$taxonomy$object_type ); ?> 

register_taxonomy_for_object_type() 用法

参数

$taxonomy

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

默认值: None

$object_type

(string) (必填) A name of the object type for the taxonomy object.

默认值: None

register_taxonomy_for_object_type() 参数

返回值

(bool) 

True if successful, false if not

register_taxonomy_for_object_type() 返回值

历史

  • 添加于 版本: 3.0.0

register_taxonomy_for_object_type() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Add an already registered taxonomy to an object type.
 *
 * @since 3.0.0
 *
 * @global array $wp_taxonomies The registered taxonomies.
 *
 * @param string $taxonomy    Name of taxonomy object.
 * @param string $object_type Name of the object type.
 * @return bool True if successful, false if not.
 */
function register_taxonomy_for_object_type( $taxonomy, $object_type) {
	global $wp_taxonomies;

	if ( !isset($wp_taxonomies[$taxonomy]) )
		return false;

	if ( ! get_post_type_object($object_type) )
		return false;

	if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) )
		$wp_taxonomies[$taxonomy]->object_type[] = $object_type;

	// Filter out empties.
	$wp_taxonomies[ $taxonomy ]->object_type = array_filter( $wp_taxonomies[ $taxonomy ]->object_type );

	return true;
}

register_taxonomy_for_object_type() 源文件

相关