Skip to content

Instantly share code, notes, and snippets.

@imvision
Created May 12, 2014 13:00
Show Gist options
  • Save imvision/a8f6c54dedb5e645f86a to your computer and use it in GitHub Desktop.
Save imvision/a8f6c54dedb5e645f86a to your computer and use it in GitHub Desktop.
Show custom post types on Tag, Archive, Author pages
<?php
// Add custom post types on Tag, Category, Author archive pages
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag() || $query->is_author) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','resource','user-post'); // 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