我已经创建了一个简单的插件来管理我的公文包作为一个自定义的帖子类型。一切正常,工作正常,但无法将我的自定义帖子类型添加到菜单中(也无法用于其分类)。注意:我已经检查了我以前知道的很多方法。(show\\u ui,show\\u in\\u nav\\u菜单,…)以下是我的CPT代码
<?php
function oseo_custom_post_type() {
register_taxonomy( \'portfolio_cat\', array(\'oseo_portfolio\'),
array(
\'show_ui\' => true,
\'hierarchical\' => true,
\'label\' => __(\'Portfolio Filters\', \'oseo-portfolio\'),
\'singular_label\' => __(\'portfolio Filter\', \'oseo-portfolio\'),
\'rewrite\' => array(\'slug\' => \'portfolio_type\')
)
);
$labels = array(
\'name\' => _x( \'Portfolios\', \'Post Type General Name\', \'oseo-portfolio\' ),
\'singular_name\' => _x( \'Portfolio\', \'Post Type Singular Name\', \'oseo-portfolio\' ),
\'menu_name\' => __( \'Portfolios\', \'oseo-portfolio\' ),
\'parent_item_colon\' => __( \'Parent Portfolio\', \'oseo-portfolio\' ),
\'all_items\' => __( \'All Portfolios\', \'oseo-portfolio\' ),
\'view_item\' => __( \'View Portfolio\', \'oseo-portfolio\' ),
\'add_new_item\' => __( \'Add New Portfolio\', \'oseo-portfolio\' ),
\'add_new\' => __( \'Add New\', \'oseo-portfolio\' ),
\'edit_item\' => __( \'Edit Portfolio\', \'oseo-portfolio\' ),
\'update_item\' => __( \'Update Portfolio\', \'oseo-portfolio\' ),
\'search_items\' => __( \'Search Portfolio\', \'oseo-portfolio\' ),
\'not_found\' => __( \'Not Found\', \'oseo-portfolio\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'oseo-portfolio\' ),
);
$args = array(
\'label\' => __( \'Portfolios\', \'oseo-portfolio\' ),
\'description\' => __( \'Portfolios\', \'oseo-portfolio\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\', \'comments\', \'custom-fields\', ),
\'taxonomies\' => array( \'portfolio_cat\' ),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => array(\'slug\' => \'portfolio\'),
\'capability_type\' => \'page\',
);
flush_rewrite_rules();
register_post_type( \'oseo_portfolio\', $args );
}
add_action( \'init\', \'oseo_custom_post_type\');
?>
我认为可能导致此问题的另一件事是,我将元盒用于此CPT。如果需要的话,我可以发布这些。
最合适的回答,由SO网友:Umashankar Chaudhary 整理而成
// portfolio code
function codenovo_portfolio_init(){
$labels = array(
\'name\' => _x(\'Portfolio\', \'post type general name\'),
\'singular_name\' => _x(\'Portfolio\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'portfolio\'),
\'add_new_item\' => __(\'Add New Portfolio\'),
\'edit_item\' => __(\'Edit Portfolio\'),
\'new_item\' => __(\'New Portfolio\'),
\'view_item\' => __(\'View Portfolio\'),
\'search_items\' => __(\'Search Portfolio\'),
\'not_found\' => __(\'No portfolio found\'),
\'not_found_in_trash\' => __(\'No portfolio found in Trash\'),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Portfolio\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'has_archive\' => false,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\'),
\'rewrite\' => array(
\'slug\' => \'portfolio\',
\'with_front\' => FALSE,
)
);
register_post_type(\'portfolio\',$args);
$labels = array(
\'name\' => _x( \'Portfolio Category\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Types\' ),
\'all_items\' => __( \'All Category\' ),
\'parent_item\' => __( \'Parent Category\' ),
\'parent_item_colon\' => __( \'Parent Category:\' ),
\'edit_item\' => __( \'Edit Category\' ),
\'update_item\' => __( \'Update Category\' ),
\'add_new_item\' => __( \'Add New Category\' ),
\'new_item_name\' => __( \'New Category Name\' ),
);
register_taxonomy(\'portfoliocategory\',array(\'portfolio\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'portifolio_category\' ),
));
}
add_action(\'init\', \'codenovo_portfolio_init\');