How to get only present and past posts with post_date

An administrator wants to make posts for a future date but not visible for visitors.
The posts come from a custom WP_Query inside my plugin so the basical WP behaviour does not work in this case.

I tried this :

$args = array(
‘post_type’ => “my-post-type”,
‘date_query’ => array(
‘before’ => ‘today’,
‘inclusive’ => true
)
);

$args[‘posts_per_page’] = -1;

return new WP_Query( $args );

But if I wrote a post with the post_date is today, it does not appear.
How can I include the post with post_date before today and today (1 second before now) ?

Read more here:: How to get only present and past posts with post_date

Leave a Reply

Your email address will not be published. Required fields are marked *