The date query for WP_Query
supports several options, including before
and after
. Using just before
, you can fetch posts from before a certain date (excluding posts from that date on):
$args = array(
'date_query' => array(
array(
'column' => 'post_date_gmt',
'before' => '1 month ago'
)
),
'posts_per_page' => -1,
);
Furthermore, you can specify whether it should be inclusive (date specified is matched as well) or not, using the inclusive
key, which defaults to false
.