Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save spencejs/5219179 to your computer and use it in GitHub Desktop.

Select an option

Save spencejs/5219179 to your computer and use it in GitHub Desktop.
Make Tags or Category Pages Query Custom Post Types In Wordpress
//Make Tags or Category Pages Query Custom Post Types
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('projects'); // replace cpt to your custom 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