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
  • You don't need the surpress filters check, if the surpress filters argument is passed to the query, your filer won't run.
    – t31os
    Commented Apr 12, 2011 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?


just to answer the second part, the syntax is:


or for multiple types:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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