Skip to content

Instantly share code, notes, and snippets.

@lswilson
Created January 20, 2013 20:23
Show Gist options
  • Save lswilson/4581437 to your computer and use it in GitHub Desktop.
Save lswilson/4581437 to your computer and use it in GitHub Desktop.
pre_get_posts() - Add CPT to Category and Tag pages
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','press_piece','knowledge_base_entries', 'nav_menu_item');
$query->set('post_type',$post_type);
return $query;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment