user3749125
user3749125

Reputation: 25

Displaying one category of post on the Wordpress posts page

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' );

Upvotes: 0

Views: 281

Answers (1)

Trotpof
Trotpof

Reputation: 116

Remove $query->is_home() condition:

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

Upvotes: 0

Related Questions