无法显示自定义分类类型的自定义分类存档页面

时间:2020-05-12 11:03:32

标签: wordpress custom-post-type permalinks custom-taxonomy

我已经使用自定义帖子类型UI设置了自定义帖子类型和自定义分类法,但是我无法使分类法存档页面正常工作。

我已经使用“自定义帖子类型永久链接”插件来实现此网址结构:

domain.com/cpt-archive/custom-taxonomy-archive/post-title
( domain.com/testpost/%testcategory%/%postname%/ )

基本的自定义帖子类型存档页面和单个帖子页面正常运行,但是分类存档页面显示“未找到结果”(例如

domain.com/testpost/category-1

这是我的CPT用户界面设置:

    // Custom Post Type
function cptui_register_my_cpts_testpost() {
$labels = [
    "name" => __( "Test Posts" ),
    "singular_name" => __( "Test Post" ),
];
$args = [
    "label" => __( "Test Posts" ),
    "labels" => $labels,
    "description" => "",
    "public" => true,
    "publicly_queryable" => true,
    "show_ui" => true,
    "show_in_rest" => true,
    "rest_base" => "",
    "rest_controller_class" => "WP_REST_Posts_Controller",
    "has_archive" => "testpost",
    "show_in_menu" => true,
    "show_in_nav_menus" => true,
    "delete_with_user" => false,
    "exclude_from_search" => false,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => true,
    "rewrite" => [ "slug" => "testpost", "with_front" => true ],
    "query_var" => true,
    "supports" => [ "title", "editor", "thumbnail" ],
    "taxonomies" => [ "testcategory" ],
];
register_post_type( "testpost", $args );
}
add_action( 'init', 'cptui_register_my_cpts_testpost' );

// Custom Taxonomy
function cptui_register_my_taxes_testcategory() {
    $labels = [
        "name" => __( "Test Categories" ),
        "singular_name" => __( "Test Category" ),
    ];
    $args = [
        "label" => __( "Test Categories" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => [ 'slug' => 'testcategory', 'with_front' => true,  'hierarchical' => true, ],
        "show_admin_column" => false,
        "show_in_rest" => true,
        "rest_base" => "testcategory",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => true,
        ];
    register_taxonomy( "testcategory", [ "testpost" ], $args );
}
add_action( 'init', 'cptui_register_my_taxes_testcategory' );

有人知道如何使该分类档案页面正常工作吗?

谢谢

0 个答案:

没有答案
相关问题