register_taxonomy_for_object_type

函数
register_taxonomy_for_object_type ( $taxonomy, $object_type )
参数
  • (string) $taxonomy Name of taxonomy object.
    Required:
  • (string) $object_type Name of the object type.
    Required:
返回值
  • (bool) True if successful, false if not.
定义位置
相关方法
unregister_taxonomy_for_object_typeregister_taxonomyunregister_taxonomyregister_post_typeregister_block_type
引入
3.0.0
弃用
-

register_taxonomy_for_object_type: 这个函数用来将已注册的分类法与WordPress中已注册的文章类型联系起来。这允许分类法被用来对相关文章类型的文章进行分组。

将一个已经注册的分类法添加到一个对象类型。

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, true ) ) {
		$wp_taxonomies[ $taxonomy ]->object_type[] = $object_type;
	}

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

	/**
	 * Fires after a taxonomy is registered for an object type.
	 *
	 * @since 5.1.0
	 *
	 * @param string $taxonomy    Taxonomy name.
	 * @param string $object_type Name of the object type.
	 */
	do_action( 'registered_taxonomy_for_object_type', $taxonomy, $object_type );

	return true;
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-16 15:35:28

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: