Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vungocthien/5dfad2a55190e9904f72493ff2b521a4 to your computer and use it in GitHub Desktop.
Save vungocthien/5dfad2a55190e9904f72493ff2b521a4 to your computer and use it in GitHub Desktop.
WordPress - Display custom post types on the same category page as your default posts
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'your-custom-posttype'); // don't forget nav_menu_item to allow menus to work!
$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