Last active
September 18, 2019 17:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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