Skip to content

Instantly share code, notes, and snippets.

@alwerner
Last active December 14, 2015 05:59
Show Gist options
  • Save alwerner/5039260 to your computer and use it in GitHub Desktop.
Save alwerner/5039260 to your computer and use it in GitHub Desktop.
Display categories for Custom Post Types, add to functions.php
// Display categories for Custom Post Types, add to functions.php
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','news'); //substitute cpt - in this case 'news' - for post type
$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