How to get previous 10 days post from a specific date – WP Query

Yes, it is possible. You can pass full date as before and after params, so:

$given_date_as_time = strtotime('2017-11-22 00:00:00');
$args = array(
    'post_type' => 'post',
    'date_query' => array(
        'before' => date( 'c', $given_date_as_time ),
        'after' => date('c', strtotime( '- 10 days', $given_date_as_time ) ),
    ),
);
$query = new WP_Query( $args );

above query is also correct and will give you result you wanted.

Leave a Comment