Skip to content

Instantly share code, notes, and snippets.

@keithdevon
Created August 13, 2014 13:29
Show Gist options
  • Save keithdevon/967d58f718825c90ce52 to your computer and use it in GitHub Desktop.
Save keithdevon/967d58f718825c90ce52 to your computer and use it in GitHub Desktop.
Custom post types in home and blog pages
// Add custom post types to the home and blog pages
// change 'cpt1' and 'cpt2' to your post type names
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'cpt1', 'cpt2' ) );
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment