Using CPT with native WP category templates

Hi,

I want to use a custom post type in a native WP category,

When i use this code, it works. I can build my template using a category and my CPT show how they should, But the template won’t appear on the front end. It reverts all archives to the generic cat templates (for every category). Almost as if this code removes any template conditions.

Any gleaming reasons why ? Thanks

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if( is_category() ) {
$post_type = get_query_var('post_type');
if($post_type)
    $post_type = $post_type;
else
    $post_type = array('nav_menu_item', 'post', 'bonus'); 
$query->set('post_type',$post_type);
return $query;
}
}

Hi Jack,

Thanks for reaching out.
It is not clear what exactly you are trying to do here, can you please explain it a bit more? The code referred to here is to override the default query variable object and as per your code you are overriding the post type with your custom post type to show the query results.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.