Don’t show older post in wordpress programmatically

I’m using “The Future Is Now!” plugin and want to display all post that are schedule for the future. The only problem is, how do i make a query like (WHERE date >= $currentdate) before i enter the loop?

    <?php if (is_category('My awesome category')) {
        $currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
        /* Some sort of query with the statement date >= $currentdate? */
    }
    ?>

    /* The Loop */
    <?php if (have_posts()) : while (have_posts()) : the_post();
    ?>

Related posts

Leave a Reply

1 comment

  1. query_posts(array('post_status' => 'future'));
    

    Edit: Above is the easy answer that fits with your loop, but as a default solution it’s better that u use a new $WP_Query object:

    $my_query = new $WP_Query;
    $my_query->query_posts(array('post_status' => 'future'));
    
    while ($my_query->have_posts()) : 
        $my_query->the_post();
        the_title();
    endwhile; 
    
    wp_reset_postdata();  // now the main wordpress query and post data is intact
    

    2nd Edit: Similar query but with a filter:

    function filter_where( $where = '' ) {
        // posts in the future
        $now = date("Y-m-d H:i:s");
        $where .= " AND post_date >= '$now'";
        return $where;
    }
    
    add_filter( 'posts_where', 'filter_where' );
    $q = new WP_Query(array('post_type' => 'post'));
    while ($q->have_posts()) : 
        $q->the_post();
        the_title();
    endwhile; 
    remove_filter( 'posts_where', 'filter_where' );