I've set up a small test query to get some posts from October 1 to October 10. I published a post today ( October 10 ) and with the date query parameter of include
set to true, I would have expected this post to show up in the query results. However, it does not.
If I alter the post's publish date to October 1, it does appear in the results. Though if I change inclusive
to false, it still appears. Basically, inclusive
doesn't appear to do anything.
If inclusive
isn't the answer, is there another way to ensure that I get all posts from October 1 to October 10 including October 1 and October 10?
$args = array(
'date_query' => array(
array(
'after' => '2014-10-01',
'before' => '2014-10-10',
'inclusive' => true
),
)
);
$posts = get_posts($args);
if( $posts ) {
foreach ($posts as $p) {
echo $p->post_title . ' on ' . $post->post_date . '<Br>';
}
} else {
echo 'no posts';
}
Edited to add that I just dumped the date query SQL and the the where clause is
" AND ( ( post_date >= '2014-10-01 00:00:00' AND post_date <= '2014-10-10 00:00:00' ) )"
So it isn't actually inclusive on the full day at all. Filtering the value to
" AND ( ( post_date >= '2014-10-01 00:00:00' AND post_date <= '2014-10-10 23:59:59' ) )"
actually includes posts made during the day of October 10.
'inclusive' => true
should now work the way that you would expect it to.