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/
This file contains 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
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