Skip to content

Instantly share code, notes, and snippets.

@ovizii
Created June 22, 2014 16:44
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 ovizii/ea32b0044da927c31926 to your computer and use it in GitHub Desktop.
Save ovizii/ea32b0044da927c31926 to your computer and use it in GitHub Desktop.
Restrict home page posts to certain categories
function my_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '11');
}
}
add_action( 'pre_get_posts', 'my_home_category' );
//If you would like to include more than one category, then just add another ID by inserting a comma and the ID number. For example, this is will display category 11 and category 14.
//$query->set( 'cat', ’11, 14’ );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment