Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#48921 closed enhancement (invalid)

WP_User_Query doesn't support querying by known user IDs

Reported by: iandunn's profile iandunn Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Users Keywords:
Focuses: Cc:

Description

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.

Change History (2)

#1 @TimothyBlynJacobs
3 years ago

I think include handles this.

#2 @iandunn
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Ah, you're right, I missed that, thanks!

Note: See TracTickets for help on using tickets.