I have run into the following issue using WP_Query:
I'm running a large query and have, therefore, split it up in batches using AJAX with an increasing offset in each loop. The issue I'm facing is that the entire process returns a few duplicates (posts from a previous loop appearing in the following one) - not always the exact same ones either.
The query looks like this:
$offset = $_POST['offset'];
$posts_per_page = 100;
$args = array(
'post_type' => array('player'),
'post_status' => 'publish',
'posts_per_page' => $posts_per_page,
'offset' => $offset,
'order' => 'DESC',
'ignore_sticky_posts' => 1,
//'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'team',
'field' => 'term_id',
'terms' => [23,46,54,12,45],
),
)
);
$posts = new WP_Query( $args );
The above is run repeatedly using AJAX, with the only thing changing being the $offset, which increases each time by 100 (equal to the previous offset plus the value of $posts_per_page) until all posts get queried.
Sample of post IDs returned:
1st loop: [...,3606,3587,3588,3569,...]
2nd loop: [3585,3586,3587,3588,3556,...]
3rd loop: [...,1594,2524,3026]
4th loop: [2524,3026,3009,...]
etc.
Any help with this would be greatly appreciated.
Similar issues I've found online but which don't seem to offer a solution that's working for me:
/
WP_Query offset is returning post from prevois loop