0

Following up on Adding arg to search results page, I want to show future posts in categories but not on the home page.

This code works:

add_action( 'pre_get_posts', function ( $q ) {
if (    !is_admin()
     && !is_feed()
     && $q->is_main_query() 
) {
    $q->set( 'post_status', ['publish', 'future'] );
}
});

but shows future posts on home page.

I tried adding && !is_home() but it doesn't work - future posts no longer show anywhere.

3

The logic inside the is_home function relies on the main query, but by definition that query hasn't happened yet as you're still in the pre_get_posts filter.

Instead, consider $q->is_home(). The same goes for is_feed() $q->is_feed()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.