0
votes

I have edited the WordPress functions.php as part of a child theme in an attempt to make the page that is set to the posts page display only 1 category.

Currently this PHP code only works for the home page - are there any edits I can make in order so that the blog/posts page only displays 1 category?

function my_home_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '123' );
    }
}
add_action( 'pre_get_posts', 'my-home_category' );
1

1 Answers

0
votes

Remove $query->is_home() condition:

function my_home_category( $query ) {
    if ( $query->is_main_query() ) {
        $query->set( 'cat', '123' );
    }
}