Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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

if ( !is_admin() ) :
function __include_future( $query )
{
    if ( $query->is_date() || $query->is_single() )
        $GLOBALS[ 'wp_post_statuses' ][ 'future' ]->public = true;
}
add_filter( 'pre_get_posts', '__include_future' );
endif;

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'!.

share|improve this answer
    
You're a genius - thank you! –  Ryan May 9 '11 at 21:46
    
I found this to be the most elegant of several solutions I found, thanks! –  Kevin C. Mar 25 '13 at 18:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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