Himas Rafeek
Posted on: 2 years ago

WP date_query pull posts 2 days ago

Your question could do with some more information, but I think this is what you are looking for:

I constructed this query from the following documentation:

https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters


                                          $today = getdate() ;
$mday = $today['mday'];
$days = 2; // Collect post for the last 2 days

$args['date_query'] = array(
    array(
        'year'  => $today['year'],
        'month' => $today['mon'],
    ),
    array(
        'day'   => array( $mday - $days, $mday ),
        'compare' => 'BETWEEN',
    ),
);