add_action( \'init\', \'create_topics_nonhierarchical_taxonomy\', 0 );
function create_topics_nonhierarchical_taxonomy() {
// Labels part for the GUI
$labels = array(
\'name\' => _x( \'Blog Tags\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Blog Tag\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search blog_tags\' ),
\'popular_items\' => __( \'Popular blog_tags\' ),
\'all_items\' => __( \'All blog_tags\' ),
\'parent_item\' => null,
\'parent_item_colon\' => null,
\'edit_item\' => __( \'Edit blog_tags\' ),
\'update_item\' => __( \'Update blog_tags\' ),
\'add_new_item\' => __( \'Add New blog_tags\' ),
\'new_item_name\' => __( \'New blog_tags Name\' ),
\'separate_items_with_commas\' => __( \'Separate blog_tags with commas\' ),
\'add_or_remove_items\' => __( \'Add or remove blog_tags\' ),
\'choose_from_most_used\' => __( \'Choose from the most used blog_tags\' ),
\'menu_name\' => __( \'Blog Tags\' ),
);
// Now register the non-hierarchical taxonomy like tag
register_taxonomy(\'blog_tags\',\'blog_tags\',array(
\'hierarchical\' => false,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'update_count_callback\' => \'_update_post_term_count\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'blog_tags\' ),
));
}
SO网友:Andy Macaulay-Brook
您的第二个参数register_taxonomy
应该是要应用分类法的帖子类型,或者是帖子类型的数组。
register_taxonomy(\'blog_tags\',\'post\',array(
\'hierarchical\' => false,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'update_count_callback\' => \'_update_post_term_count\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'blog_tags\' ),
));
将为内置
post
岗位类型。
SO网友:Chintan Sartape
您需要做的是指定正在使用的自定义帖子类型和正在注册的分类法。在代码中,您使用blog_tags
这两种情况都适用,但这行不通。
如果要添加tag
分类法blogs
自定义帖子类型,您可以使用以下方法执行此操作:
register_taxonomy(\'tag\', \'blogs\', array(
\'hierarchical\' => false,
\'labels\' => $labels,
\'show_ui\' => true,
\'update_count_callback\' => \'_update_post_term_count\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'tag\' ),
));