pre_get_posts and the blog page

Your blog page is actually your home page, so you need to use is_home(). For the static frontpage, is_front_page() would be used

EDIT

Sorry for being confusing :-). This how it works when a static frontpage is set

The page set as your frontpage is actaully just a cover page. When you think of a book, this is the page that will tell the reader what the book is all about. The page used here will be the custom page template set by you. The correct naming should be front-page.php, but any page template will do. The proper conditional tag to use here will be is_front_page()

Now, the blogpage, whether explicitely set or not, will either use home.php, and if that is not available, will use index.php. Not many people knows this, but this is regarded as your site’s homepage, the normal index page you will see when a static frontpage is not set. To target your blogpage, you’ll need to use is_home() conditional check. Strange, but true

To restrict your blogpage to one category only, use pre_get_posts as you did, just change your conditional tag accordingle

function only_one_cat_blogpage($query) {
    if( !is_admin() && $query->is_home() && $query->is_main_query() ){
        $query->set( 'cat', 'ID OF CATEGORY' );
    }
}
add_action( 'pre_get_posts', 'only_one_cat_blogpage' );

EDIT 2

For further reading, check out

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)