Skip to content

Instantly share code, notes, and snippets.

@wking-io
Last active September 18, 2019 17:24
Show Gist options
  • Select an option

  • Save wking-io/811960502018d5d010483bf77fa80605 to your computer and use it in GitHub Desktop.

Select an option

Save wking-io/811960502018d5d010483bf77fa80605 to your computer and use it in GitHub Desktop.
Filter out posts from index page to show only one specific category
function customize_query ( $query ) {
// Make sure this is only effecting the public side
if ( ! is_admin() ) :
// Make sure this is a query for the post page and is the main query for the page
if ( is_home() && $query->is_main_query() ) :
// Set query to only pull posts from the specified category
$query->set( 'category_name', 'Newsletter' );
endif;
endif;
}
add_action( 'pre_get_posts', 'customize_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment