wordpress: only show posts from today or the future

php, wordpress

Solution

$future_args = array(
    'post_status' => 'future'
    // possibly further query arguments
);

$today = getdate();
$today_args = array(
    'year' => $today['year'],
    'monthnum' => $today['mon'],
    'day' => $today['mday'] 
    // possibly further query arguments
);

$future_query = new WP_Query( $future_args );
$today_query = new WP_Query( $today_args );

while ( $today_query->have_posts() ) :
    $today_query->the_post();
    // echo something
endwhile;
wp_reset_postdata();

while ( $future_query->have_posts() ) :
    $future_query->the_post();
    // echo something
endwhile;
wp_reset_postdata();

That ought to do it.

See the codex article on the WP_Query class for reference.

Problem

I am running this query to print out my posts. It works but I want to add a parameter that tells the system to only display posts that are from today or will be published in the future! Here is the query: ``` $today = getdate(); $year=$today["year"]; $month=$today["mon"]; $day=$today["mday"]; query_posts( $query_string.'order=ASC' . '&post.status=future,publish' . '&year='.$year . '&monthnum='.$month ); ``` I tried to do something like `&post.date = <= $today` but that didn't work. please, can anyone tell me how to do it? My idea is to tell the query to only show posts with a publishing-date that is today or "less" than today. That's why the `" <= "` .

Original source

Related problems