Skip to content

Instantly share code, notes, and snippets.

@renventura
Created November 21, 2014 01:45
Show Gist options
  • Save renventura/bec76f425fed5d8ec20c to your computer and use it in GitHub Desktop.
Save renventura/bec76f425fed5d8ec20c to your computer and use it in GitHub Desktop.
Show recent custom post types on your blog's home page rather than Posts.
<?php //* Mind the opening PHP tag
/*
* Changes the main query on the home page (blog posts index) to one or more custom post types
*/
add_filter( 'pre_get_posts', 'my_custom_query' );
function my_custom_query( $query ) {
if ( $query->is_main_query() && $query->is_home() ) {
$query->set( 'post_type', array( 'nfl', 'nba', 'mlb', 'nhl', 'ncaaf', 'ncaab' ) );
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment