Skip to content

Instantly share code, notes, and snippets.

@h1dd3nsn1p3r
Last active August 20, 2016 10:32
Show Gist options
  • Select an option

  • Save h1dd3nsn1p3r/f0b06c453b5185ba016654022f97e1fe to your computer and use it in GitHub Desktop.

Select an option

Save h1dd3nsn1p3r/f0b06c453b5185ba016654022f97e1fe to your computer and use it in GitHub Desktop.
Adding custom post type support in functions.php file to show custom posts types in category, tags & archives.
/*
display / Show custom post types posts in Archive, tags & categories.
*/
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('nav_menu_item','post','custom_posttype1', 'custom_posttype2', 'custom_posttype3', 'custom_posttype4');
}
$query->set('post_type',$post_type);
return $query;
}
}
add_filter('pre_get_posts', 'query_post_type');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment