Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
share|improve this question
    
You don't need the surpress filters check, if the surpress filters argument is passed to the query, your filer won't run. –  t31os Apr 12 '11 at 13:26

2 Answers 2

function post_type_tags_fix($request) {
    if ( isset($request['tag']) && !isset($request['post_type']) )
    $request['post_type'] = 'any';
    return $request;
} 
add_filter('request', 'post_type_tags_fix');

You can alter the post type to your liking. From this post. Custom post type tag archives don't work for basic loop?

share|improve this answer

just to answer the second part, the syntax is:

example.com/tag/blue?post_type[]=custom
example.com/tag/blue?post_type[]=post

or for multiple types:

example.com/tag/blue?post_type[]=custom&post_type[]=post
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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