Skip to content

Instantly share code, notes, and snippets.

Created Jul 19, 2015
What would you like to do?
How to limit Posts on Posts page to a specific Category in WordPress.
add_action( 'pre_get_posts', 'sk_show_posts_from_a_category_posts_page' );
* Show Posts from a specific category on Posts page
* @author Bill Erickson
* @author Sridhar Katakam
* @link
* @param object $query data
function sk_show_posts_from_a_category_posts_page( $query ) {
if( $query->is_main_query() && !is_admin() && is_home() ) {
$query->set( 'category_name', 'category-1' ); // Replace "category-1" with your category slug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment