This PHP code enables you to display posts from 1 or more specific categories ( by category ID ) on the 1st page of your paginated home page or what some call posts page or blog page.
Add the code to the end of your child themes functions file :
add_action( 'pre_get_posts', 'specific_cat_first_posts_page' ); function specific_cat_first_posts_page($query) { if ( get_query_var( 'paged' ) >= 0 ) return; if ( ! is_admin() && $query->is_home() && $query->is_main_query() ){ $query->set( 'cat', '611' ); } }
Swap out the 611 with the category ID for your posts category.
You can also add an array of category id’s like this :
$query->set( 'cat', array('1','2,'3') );
Was This Tutorial Helpful?