WP REST API only returning partial list of users

To anyone who might still be hitting this problem, here’s a checklist:

  1. Make sure you are authenticated AND your user has the list_users capability.

Example: When adding a custom role, I make sure to add the list_users capability. The user should also be logged in (what authenticated means) when making the request.

  1. By default, only users who have published posts are returned by the request. To disable this, you can remove has_published_posts from the query args, like so:

Add normally

add_filter('rest_user_query', 'remove_has_published_posts_from_api_user_query', 10, 2);
function remove_has_published_posts_from_api_user_query($prepared_args, $request)
{
    unset($prepared_args['has_published_posts']);

    return $prepared_args;
}

or within namespace

add_filter('rest_user_query', __NAMESPACE__ . '\remove_has_published_posts_from_api_user_query', 10, 2);
function remove_has_published_posts_from_api_user_query($prepared_args, $request)
{
    unset($prepared_args['has_published_posts']);

    return $prepared_args;
}

Leave a Comment