1

I'd like my archive.php page's daily view (is_day) to display scheduled posts (post_status=future). For example, if I go to mysite.com/2011/05/20 I would see all posts scheduled to appear on May 20.

The archive page's loop starts with:

if ( have_posts() )
the_post();

and ends with:

rewind_posts();
get_template_part( 'loop', 'archive' );

Do I need to make a second loop, or can I modify this single loop to show scheduled posts? If so, how? Thank you.

1 Answer 1

7

Keep things simple - leave your archive templates alone and place this in your functions.php;

add_action( 'pre_get_posts', function ( $wp_query ) {
    global $wp_post_statuses;

    if (
        ! empty( $wp_post_statuses['future'] ) &&
        ! is_admin() &&
        $wp_query->is_main_query() && (
            $wp_query->is_date() ||
            $wp_query->is_single()
        )
    ) {
        $wp_post_statuses['future']->public = true;
    }
});

Essentially, it says;

If we're on a date archive, or viewing a single post, make future posts publicly visible.

As a result, WordPress behaves normally when you view archives for any given date, except now it also includes posts 'from the future'!.

1
  • I found this to be the most elegant of several solutions I found, thanks!
    – Kevin C.
    Mar 25, 2013 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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