404 - Taxonomy Archive Page

时间:2020-04-17 作者:JBol

我正在创建一个Wordpress自定义帖子类型,包括一个分类法,在安装之后,所有的永久链接都被刷新了,但是分类法归档页面不断给我404。

CPT归档页面工作得非常好。

要创建的代码:

add_action( \'init\', \'register_cpt_post_type\' );
function register_cpt_post_type() {
    register_post_type( \'offers\',
        array(
            \'labels\' => array(
                \'name\' => \'Offer Posts\',
                \'menu_name\' => \'Offers Manager\',
                \'singular_name\' => \'Offer post\',
                \'all_items\' => \'All Offers Posts\'
            ),
            \'public\' => true,
            \'publicly_queryable\' => true,
            \'show_ui\' => true,
            \'show_in_menu\' => true,
            \'show_in_nav_menus\' => true,
            \'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'comments\', \'post-formats\', \'revisions\' ),
            \'hierarchical\' => false,
            \'has_archive\' => \'offers\',
            \'show_in_rest\' => true,
            \'taxonomies\' => array(\'offers-category\')
        )
    );
    register_taxonomy( \'offers-category\', array( \'offers\' ),
        array(
            \'labels\' => array(
                \'name\' => \'Offer Categories\',
                \'menu_name\' => \'Offer Categories\',
                \'singular_name\' => \'Offers Category\',
                \'all_items\' => \'All Categories\'
            ),
            \'public\' => true,
            \'hierarchical\' => true,
            \'show_ui\' => true,
            \'show_in_rest\' => true,
            \'rewrite\'=>array( \'slug\'=>\'offers\' )
        )
    );
}
如果我尝试访问www.xxx。com/offers->它工作得非常好,并为我提供了存档页面模板

如果我尝试访问www.xxx。com/offers/food->如果食品是一个类别,页面将指向404。

如果我设置了一些错误,你能指导我吗?

1 个回复
SO网友:Alberto Marin

分类法使用与自定义帖子类型相同的slug。如果可能,请尝试用不同的名称重写自定义分类法或自定义post类型slug,或者尝试此处建议的解决方案:Add category base to url in custom post type/taxonomy

相关推荐