这里缺少一些基本的东西。这是我的CPT代码。。。
// Create a custom post type
//
add_action( \'init\', \'custom_post_type_func\' );
function custom_post_type_func() {
//posttypename = PDSH Posts
$labels = array (
\'name\' => _x( \'PDSH Posts\', \'pdsh_posts\' ),
\'singular_name\' => _x( \'PDSH Post\', \'pdsh_posts\' ),
\'add_new\' => _x( \'Add New\', \'pdsh_posts\' ),
\'add_new_item\' => _x( \'Add New PDSH Post\', \'pdsh_posts\' ),
\'edit_item\' => _x( \'Edit PDSH Post\', \'pdsh_posts\' ),
\'new_item\' => _x( \'New PDSH Post\', \'pdsh_posts\' ),
\'view_item\' => _x( \'View PDSH Post\', \'pdsh_posts\' ),
\'search_items\' => _x( \'Search PDSH Posts\', \'pdsh_posts\' ),
\'not_found\' => _x( \'No PDSH Posts found\', \'pdsh_posts\' ),
\'not_found_in_trash\' => _x( \'No PDSH Posts found in Trash\', \'pdsh_posts\' ),
\'parent_item_colon\' => _x( \'Parent PDSH Post:\', \'pdsh_posts\' ),
\'menu_name\' => _x( \'PDSH Posts\', \'pdsh_posts\' ),
);
$args = array (
\'labels\' => $labels,
\'hierarchical\' => true,
\'description\' => \'Hi, this is my custom post type.\',
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
\'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\'
);
register_post_type( \'pdsh_posts\', $args );
}
效果很好!我正在使用WP All Import插件创建3378篇PDSH帖子,其中包含三个父类别:字母、创建者、道德。他们在这里看起来都很正常。。。
但当我查看其中一个类别时,归档页面无法看到帖子,转到“无内容”,抛出一个“未找到”。我是否需要以某种方式注册所有106个类别,或者只注册三个父类别?
更新日期:
以下是我的注册尝试;按字母顺序排列;和;“A”;。。。
//
// Hook into the init action and call create_book_taxonomies when it fires
//
add_action( \'init\', \'create_post_types_hierarchical_taxonomy\', 0 );
// Create a custom taxonomy name it subjects for your posts
function create_post_types_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
// //first do the translations part for GUI
$labels = array(
\'name\' => _x( \'Alphabetical\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Alphabetical\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Alphabetical\' ),
\'all_items\' => __( \'All Alphabetical\' ),
\'parent_item\' => __( \'Parent Alphabetical\' ),
\'parent_item_colon\' => __( \'Parent Alphabetical:\' ),
\'edit_item\' => __( \'Edit Alphabetical\' ),
\'update_item\' => __( \'Update Alphabetical\' ),
\'add_new_item\' => __( \'Add New Alphabetical\' ),
\'new_item_name\' => __( \'New Alphabetical Name\' ),
\'menu_name\' => __( \'Alphabetical\' ),
);
// Now register the taxonomy
register_taxonomy(\'Alphabetical\',array(\'A\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_in_rest\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'Alphabetical\' ),
));
}