0

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.com/offers -> that works perfectly fine and gives me the archive page template

If I try access www.xxx.com/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?

2
  • You did Permalink Change in your admin setting – HK89 Apr 17 '20 at 9:04
  • @HK89 - Yes I have flushed the permalinks several times already – JBol Apr 17 '20 at 9:28
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.