Started working with the WP REST API for the first time. Our ultimate goal is to dynamically load UI elements based on which user is presently logged in. However, my attempts to pull a list of all users is hitting a wall - I'm only able to return two users out of five when running the base http request:


I tried including other params like search but that will only work if the user I'm searching for is one of the two in the response I'm already getting; it doesn't return any data for the other three users whatsoever. Looking at the user profiles, there aren't any unique data points or roles that set the two users being returned apart from the other three. The two being returned are both administrators, but so is one of the three that is missing.

What on Earth am I missing??

  • 2
    when no user is connected, only users with published posts are retrieved. to connect a user for a API call, look this : developer.wordpress.org/rest-api/using-the-rest-api/…
    – mmm
    Commented Apr 17, 2018 at 18:14
  • This doesn't appear to be the case. One of the two users showing in the response did create a post (that was deleted), but the other has had zero activity. And one of the three that isn't showing in the response has made several comments in activity feeds elsewhere on the site. I would think if this were a true statement, then any user without rights to create posts would never show in the response and that just doesn't seem correct. Commented Apr 17, 2018 at 19:02

3 Answers 3


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)

    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)

    return $prepared_args;
  • 1
    unbelievable, I can't believe there was a 'published post' filter in there all along. This fixed it for me!
    – gray
    Commented Mar 17, 2020 at 19:51
  • 2
    right? this is why I have a love/hate relationship with WP
    – Abe Caymo
    Commented Mar 18, 2020 at 11:40
  • Such an underrated answer. Thank you, Abe!
    – Johan
    Commented Aug 17, 2022 at 10:33

I think it depends on the specifics on what your looking for, you can gain the most control by making your own route tough, the users route is more meant to list out users, not exactly search them as there is a pretty crazy amount of stuff you could be wanting to search based off of, and doing that all through parameters might get difficult.

I am not saying it cannot be done, I just found personally that rather then fighting to get a route to follow your use case, building out custom routes is easier.

Here is an example:

// namespace is like app/v1 rather then wp/v2
register_rest_route($namespace, '/users', array(
    'methods'             => WP_REST_Server::READABLE,
    'callback'            => 'get_user_list',
    'show_in_rest' => true

then for the function get_user_list

function get_user_list($request) {
   //below you can change to a WQ_Query and customized it to ensure the list is exactly what you need
   $results = get_users();

   //Using the default controller to ensure the response follows the same structure as the default route
   $users = array();
   $controller = new WP_REST_Users_Controller();
   foreach ( $results as $user ) {
        $data    = $controller->prepare_item_for_response( $user, $request );
        $users[] = $controller->prepare_response_for_collection( $data );

   return rest_ensure_response( $users );

Of course there is more too it (like pagination).

https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php will show you how it builds the standard route through the get_items function. Depending on what you want to query by it could also tell you the options you need to query by (if using the default route).

The only reason I am giving such a complicated answer as it could help you learn the ins and out of how it works and what application of the REST API might suite your needs.

  • Thanks Jordan but this doesn't address the original question - why can't we access all users and how to fix that. I appreciate the extra insight, but this answer does overcomplicated the situation for our particular use case. We'll be searching with the username, so simply running an HTTP request like http://portal.alliedbuildings.com/wp-json/wp/v2/users?search=dblackburn is much simpler and easier to troubleshoot. Commented Apr 17, 2018 at 19:13
  • I understand, I am not expecting this to be accepted as the answer, but I do like to answer like this at times since I end up in stackoverflow looking for a more broad answer after hours of searching, this is more of a last resort. Commented Apr 17, 2018 at 19:32

After much reading I found the reason why all users are not returned with the straight-forward HTTP request for WP REST API:

This is a non-authenticated request, therefore only publicly available users data is released in a GET request.

*** It's important to mention that if some data you need is unavailable, you probably need to add those fields to responses, using register_api_fields (see docs for example usage), to your user endpoints as well.

The best resource I found, which gave me this answer, was part of the detailed and easy-to-read guide on the WP REST API from Torque (see pages 35-38). Someone needs to buy that man many, many beers for writing such a great guide!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.