Take the 2-minute tour ×

How to display a list of posts from today date to future? I am actually using this code:

<div id="news-loop">
<?php if (have_posts()) : ?>
                <?php query_posts('cat=4&showposts=6&orderby=date&order=DESC&post_status=future&post_status=published'); while (have_posts()) : the_post(); ?>
                <p><?php the_time('j F, Y') ?></p>
            <?php endwhile; ?>
        <?php else : ?>
   <?php endif; ?>

This is showing correctly all the posts and future posts for that category.

An additional problem is: since I'm using "post_status=future&post_status=published" I have to trash the old posts to avoid them being displayed.

Thanks for your help!

share|improve this question

3 Answers 3

up vote 1 down vote accepted

According to query_posts you could do a filtering function like:

function filter_where( $where = '' ) {
    // where post_date > today
    $where .= " AND post_date >= '" . date('Y-m-d') . "'"; 
    return $where;
add_filter( 'posts_where', 'filter_where' );

And then your query_posts doesn't need to have post_status

share|improve this answer
This seems the way to go, but practically I copied the above code into functions.php, removed post_status from the query and all the articles disappeared. Also, I need this applied only to one category. Sorry if I didn't catch it immediately but I'm not a programmer :) –  Andycap Feb 28 '11 at 10:16
Solved! thanks, my mistake was putting it in functions.php Works perfectly! –  Andycap Feb 28 '11 at 21:20

first change you query_posts(...) to this:

$args = array(
        'cat' => 4,
        'posts_per_page' => 6,
        'orderby' => 'date',
        'order' => 'DESC',
        'post_status' =>array('future','published'));

then add this code to your theme's functions.php file

function my_filter_where( $where = '' ) {

    global $wp_query;

    if (is_array($wp_query->query_vars['post_status'])){

        if (in_array('future',$wp_query->query_vars['post_status']){
        // posts today into the future
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('now')) . "'";
    return $where;
add_filter( 'posts_where', 'my_filter_where' );

now this is assumming that this is the only query that includes future posts otherwise you need to add a conditional parameter to the query and check for it in the filter function.

share|improve this answer
Thanks for this, it actually solved this question - wordpress.stackexchange.com/questions/104574/… and several attempts from me and various people. 3 days of attempts, solved in 5mins! –  Rob Jul 3 '13 at 15:28

I'm not sure if post_status=future&post_status=published is the intended way. I guess it's like with orderby=date whatever just separated with a space. What happens if you just let published out of the query? I guess that's why you might bring up old posts. So far i got the only idea i got the filter out not already published future posts is a 2step process. The following is not tested and won't work out of the box. It should just give you an idea on where to look into the $post object and how to possibly avoid displaying posts that don't fit into your query.

$future_posts = query_posts( 'cat=4&showposts=6&orderby=date&order=DESC&post_status=future' );
if ( $future_posts->have_posts() ) :
  while ( $future_posts->have_posts()) : 

    if ( $post['post_status'] !== 'published' ) :
       // do stuff

share|improve this answer

Your Answer


