[wp-trac] [WordPress Trac] #48921: WP_User_Query doesn't support querying by known user IDs

WordPress Trac noreply at wordpress.org
Mon Dec 9 16:46:12 UTC 2019


#48921: WP_User_Query doesn't support querying by known user IDs
-------------------------+-----------------------------
 Reporter:  iandunn      |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Users        |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 It has parameters like `login__in` to allow for querying for users in a
 list of known usernames, but there doesn't appear to be a similar way to
 query for all of the users who match a list of IDs.

 I wonder if that wasn't added because it was assumed that if you had the
 user IDs, you'd already have the user objects? There are cases where that
 isn't true, though. For example, I'm trying to pull data from `wp_users`,
 `wp_bp_xprofile_data` (BuddyPress), and custom post type. All of those
 sources have some data related to the user, and I want to combine it all
 and display it.

 I first query against `wp_bp_xprofile_data` -- for performance and
 business logic reasons -- and that gives me part of the data, and the
 `user_id`. Next, I need to pull some info from `wp_users` for each of
 those IDs.

 Currently I need a custom query to do that, but it seems like it should be
 possible with something like `get_users( array( 'ids__in' => $user_ids )
 )` where `$user_ids` is an array of IDs.

 In this case there are thousands of users, so it wouldn't be performant to
 do individual `get_user_by()` queries, etc.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48921>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list