I have written a WP_query with a date range.
$args = array(
'date_query' => array(
array(
'column' => 'post_date_gmt',
'after' => array('year' => $after[0], 'month' => $after[1], 'day' => $after[2])
),
array (
'column' => 'post_date_gmt',
'before' => array('year' => $before[0], 'month' => $before[1], 'day' => $before[2])
)
),
'posts_per_page' => -1,
'inclusive' => false,
);
$posts = new WP_Query( $args );
which works perfectly when I output the sql and run it in phpmyadmin.
SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND ( wp_posts.post_date_gmt > '2015-01-11 23:59:59'
AND wp_posts.post_date_gmt < '2015-01-17 00:00:00' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
ORDER BY wp_posts.post_date DESC
However the loop prints out more posts
if ( $posts->have_posts() ) :
while ( $posts->have_posts() ) : $posts->the_post();
I have tried using the reset loop functions but with no luck. What am I doing wrong. This is in a page template that is trying to mimic archive.
Thanks
Chris
$posts
object and see what's going on there.found_posts
, but 11posts_count
, this seems plain invalid. There can't be more results than there can possibly be results. Is anything else at all possibly manipulating the$posts
variable? Can you try this with plugins disabled.