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).

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');
        $post_type = $post_type;
        $post_type = array('post','cpt'); // replace cpt to your custom 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

I am not entirely sure if this will help or not, but I found an article that lets you add post types to the main post loop: http://bajada.net/2010/06/08/custom-post-types-in-the-loop-adding-a-filter-on-pre_get_posts

share|improve this answer
Thanks, that didn't quite work for me, but I did find something that did (included above). Still trying to find a solution for the second part. –  user3903 Mar 13 '11 at 11:20

Your Answer


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.