Skip to content

Instantly share code, notes, and snippets.

@NeilJS
Created March 19, 2012 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeilJS/2115105 to your computer and use it in GitHub Desktop.
Save NeilJS/2115105 to your computer and use it in GitHub Desktop.
WP - Ensure custom post types work with category and tag searches
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$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;
}
}
// source: http://wordpress.org/support/topic/custom-post-type-tagscategories-archive-page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment