admin管理员组

文章数量:1387346

I am creating a Wordpress Custom Post Type including a taxonomy, after installing, all permalinks where flushed, however the taxonomy archive page is constantly giving me 404.

The CPT archive page works perfectly fine.

Code to create:

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' )
        )
    );
}

If I try access www.xxx/offers -> that works perfectly fine and gives me the archive page template

If I try access www.xxx/offers/food -> Where food is a category created, page leads to 404.

Can you some please guide me if I am setting up something wrong?

I am creating a Wordpress Custom Post Type including a taxonomy, after installing, all permalinks where flushed, however the taxonomy archive page is constantly giving me 404.

The CPT archive page works perfectly fine.

Code to create:

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' )
        )
    );
}

If I try access www.xxx/offers -> that works perfectly fine and gives me the archive page template

If I try access www.xxx/offers/food -> Where food is a category created, page leads to 404.

Can you some please guide me if I am setting up something wrong?

Share Improve this question asked Apr 17, 2020 at 8:29 JBolJBol 1 2
  • You did Permalink Change in your admin setting – HK89 Commented Apr 17, 2020 at 9:04
  • @HK89 - Yes I have flushed the permalinks several times already – JBol Commented Apr 17, 2020 at 9:28
Add a comment  | 

1 Answer 1

Reset to default 0

The taxonomy is using the same slug as your custom post type. Try to rewrite the custom taxonomy or custom post type slug with different names if possible or try the solution suggested here: Add category base to url in custom post type/taxonomy

本文标签: custom post types404Taxonomy Archive Page