I’m using custom post types, but they don’t appear on tag pages along with regular posts and i’d like to include both standard and custom post types on tag or category pages.
What would be required before the loop to include all posts? (including custom type).
Updated:
To add, I found this code here, which worked perfectly for the first part:
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;
else
$post_type = array('post','cpt'); // replace cpt to your custom post type
$query->set('post_type',$post_type);
return $query;
}
}
Second question still remains though:
Is there a way to allow readers to filter by post type?
So either of the following would work..
example.com/tag/blue?post_type=custom
example.com/tag/blue?post_type=post
You can alter the post type to your liking.
From this post.
Custom post type tag archives don’t work for basic loop?
just to answer the second part, the syntax is:
or for multiple types: