我刚刚将我所有的博客帖子都转换为CPT,因为我需要它们具有层次结构。问题是,我为所有的帖子都分配了类别。如何在我的CPT中使用标准WordPress类别?
我尝试添加\'taxonomies\' => array(\'category\'),
到register_post_type
功能,但不起作用。我试过了register_taxonomy_for_object_type( \'category\', \'illustrations\' )
这也没用。
有什么建议吗?
更新:感谢所有人的回复,但如上所述,我两次都试过了\'taxonomies\' => array(\'category\')
和\'taxonomies\' => array(\'category\'),
两者都不起作用。
下面是整个register\\u post\\u type函数-带有“taxonomies”参数:
/* Register the \'Illustrations\' post type */
register_post_type(
\'illustrations\',
array(
\'label\' => \'illustrations\',
\'description\' => \'\',
\'public\' => true,
\'menu_icon\' => get_bloginfo( \'template_directory\' ) . \'/images/help-icon.png\',
\'show_ui\' => true,
\'show_in_menu\' => true,
\'capability_type\' => \'post\',
\'taxonomies\' => array( \'category\' ),
\'has_archive\' => true,
\'hierarchical\' => true,
\'rewrite\' => array( \'slug\' => \'\' ),
\'query_var\' => true,
\'supports\' => array( \'title\', \'editor\', \'custom-fields\', \'thumbnail\', \'page-attributes\', \'revisions\', \'comments\',\'author\' ),
\'labels\' => array (
\'name\' => \'Illustrations\',
\'singular_name\' => \'Illustration\',
\'menu_name\' => \'Illustrations\',
\'add_new\' => \'Add Illustration\',
\'add_new_item\' => \'Add new Illustration\',
\'edit\' => \'Edit\',
\'edit_item\' => \'Edit illustration\',
\'new_item\' => \'New illustration\',
\'view\' => \'View illustration\',
\'view_item\' => \'View illustration\',
\'search_items\' => \'Search illustrations\',
\'not_found\' => \'No Illustrations Found\',
\'not_found_in_trash\' => \'No Illustrations Found in Trash\',
\'parent\' => \'Parent Illustration\',
), ) );
register_taxonomy_for_object_type( \'category\', \'illustrations\' );
SO网友:Nicolai Grossherr
您需要使用taxonomies argument
像这样:
\'taxonomies\' => array(\'category\')
在您的
register_post_type
密码
其他信息:http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
<小时>
Update:
/* Register the \'Illustrations\' post type */
add_action( \'init\', \'wpse114838_reg_pt_illustrations\');
function wpse114838_reg_pt_illustrations() {
register_post_type(
\'illustrations\',
array(
\'labels\' => array (
\'name\' => \'Illustrations\',
\'singular_name\' => \'Illustration\',
\'menu_name\' => \'Illustrations\',
\'add_new\' => \'Add Illustration\',
\'add_new_item\' => \'Add new Illustration\',
\'edit\' => \'Edit\',
\'edit_item\' => \'Edit illustration\',
\'new_item\' => \'New illustration\',
\'view\' => \'View illustration\',
\'view_item\' => \'View illustration\',
\'search_items\' => \'Search illustrations\',
\'not_found\' => \'No Illustrations Found\',
\'not_found_in_trash\' => \'No Illustrations Found in Trash\',
\'parent\' => \'Parent Illustration\',
),
\'label\' => \'illustrations\',
\'description\' => \'\',
\'public\' => true,
\'menu_icon\' => get_bloginfo( \'template_directory\' ) . \'/images/help-icon.png\',
\'show_ui\' => true,
\'show_in_menu\' => true,
\'capability_type\' => \'post\',
//you need just one of the methods, uncomment the one you want
//\'taxonomies\' => array( \'category\' ),
\'has_archive\' => true,
\'hierarchical\' => true,
\'rewrite\' => array( \'slug\' => \'\' ),
\'query_var\' => true,
\'supports\' => array( \'title\', \'editor\', \'custom-fields\', \'thumbnail\', \'page-attributes\', \'revisions\', \'comments\',\'author\' ),
)
);
//you need just one of the methods, uncomment the one you want
//register_taxonomy_for_object_type( \'category\', \'illustrations\' );
}
这是基于您问题中的代码。我测试了它
register_taxonomy_for_object_type( \'category\', \'illustrations\' );
或
\'taxonomies\' => array( \'category\' )
- 方法,它正在发挥作用。只需使用其中一个,两个都做没有意义,请在上面的代码中取消注释所需的一个。你可能没有像“EricHolmes”和“Howdy\\u McGee”所建议的那样参与初始化操作。