Skip to content

Instantly share code, notes, and snippets.

@srikat
Created Jul 19, 2015
Embed
What would you like to do?
How to limit Posts on Posts page to a specific Category in WordPress. https://sridharkatakam.com/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 http://www.billerickson.net/customize-the-wordpress-query/
* @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