0
votes

I created a custom post type using the Custom Post Type UI Plugin and made it support archives. I have a CPT called Listing. I am using the following function to have all the pages default to my CPT. Everything works great except the the www.myURL.com/category page, which displays a 404 Error.
I'd like this page to display all the posts that exist as part of this CPT.

add_filter('pre_get_posts', 'query_post_type');

function query_post_type($query) {
  if(is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $post_type = get_query_var('post_type');
     if($post_type) {

    $post_type = $post_type; //print 'test';
}
else {
    $post_type = array('post','listing', 'nav_menu_item');  //print '2nd';
    $query->set('post_type',$post_type);
    return $query;
    }
   }
}
2
Have you found the solution for this?leonardeveloper

2 Answers

1
votes

If you want to create custom post type archive page then first create this file archive-{posttype}.php like archive-test.php.

For more information follow this link. I m sure this will work

0
votes

www.myURL.com/category will 404 as this URL is not available in the template hierarchy. This not only happens for category, but also for other archives like author and custom taxonomies. I know that there was a trac ticket raised for this to include index pages for this, but it was rejected.

The only way to get around this is to create a page, create a custom query on it to display what is needed and naming the page slug category. You just have to remember, you cannot have child pages for this page.