Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Show custom post types on tag, category and archive pages in Wordpress

View gist:1055880
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
/**
* Also show custom post types in tag/category/archive pages
*/
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_post_type','another_custom_post_type');
}
$query->set('post_type',$post_type);
return $query;
}
}
add_filter('pre_get_posts', 'query_post_type');
?>

Thanks @boyvanamstel, your function works great! I hope soon Wordpress.org could fix this error inside the core :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.