get_users is missing or skipping over users in loop


I want to paginate through all users in a WP site in groups of 100. The code below is a simplified version:

for($offset = 0; $offset < 100; $offset++)

    $args = ["number" => 100, 'orderby' => 'ID'];

    $args['offset'] = ($offset - 1) * (int) $args['number'];

    $users = get_users($args);
    //Do Stuff with $users



The issue is that I seem to be skipping over some Users. I’ve logged the User IDs from the loop and checked them against the Users section in the dashboard, I can find User IDs that don’t appear in the logs but do appear in Users.

I’m aware there is also a ‘paged’ parameter but I got the same result when using it.

Anyone seen anything like this before?

Colin 2 years 2020-12-14T09:10:23-05:00 0 Answers 9 views 0

Leave an answer