I need to create a landing page which only shows posts that are at least a month old.
Everything I’ve read / tried with the date query so far seems aimed at including posts between the last month and now rather than excluding..
effectively I’m looking to exclude posts between todays date and today-1month.
Any pointers appreciated.
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
.