WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 4 years ago

#22057 closed enhancement (fixed)

WP_User_Query by default doesn't return the meta values

Reported by: markoheijnen Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.5
Component: Users Keywords: dev-feedback needs-patch
Focuses: Cc:
PR Number:

Description

When calling WP_User_Query it is by default not returning the meta values since it isn't creating a WP_User object. I was wondering if it should be able to return those values.

Currently this from the code that got added in #18428

Attachments (2)

22057.diff (1.3 KB) - added by ryan 7 years ago.
Minimal attempt to return WP_User objects for 'all'
22057-ut.diff (1.8 KB) - added by ryan 7 years ago.

Download all attachments as: .zip

Change History (12)

#1 @DrewAPicture
7 years ago

  • Cc xoodrew@… added

#2 @knutsp
7 years ago

  • Cc knut@… added
  • Keywords needs-patch added
  • Type changed from defect (bug) to enhancement

#3 @nacin
7 years ago

If you call fields => all_with_meta, you'll get user objects back.

#4 @ryan
7 years ago

Do we need all_with_meta now that WP_User loads meta on demand? We could always return WP_User objects from WP_User_Query and avoid the unconditional update_meta_cache() call in cache_users(). That leaves deciding whether to slurp * from the users table like 'all' does or slurp the IDs and then pass to cache_users() to query for users not already cached (with update_meta_cache() removed) like all_with_meta does.

#5 follow-up: @ryan
7 years ago

Perhaps: Make all_with_meta a synonym for all. Always do the split style query for all. Introduce some cache control flags similar to cache_results and update_post_meta_cache used in WP_Query. Always return WP_User objects.

#6 in reply to: ↑ 5 @nacin
7 years ago

Replying to ryan:

Perhaps: Make all_with_meta a synonym for all. Always do the split style query for all. Introduce some cache control flags similar to cache_results and update_post_meta_cache used in WP_Query. Always return WP_User objects.

Works for me.

#7 @scribu
7 years ago

+1 for always returning WP_User objects. Also:

if ( 'all_with_meta' == $q['fields'] ) {
  $q['fields'] = 'all';
  $q['cache_results'] = true;
}

@ryan
7 years ago

Minimal attempt to return WP_User objects for 'all'

@ryan
7 years ago

#8 @ryan
7 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [22248]:

Return WP_User objects when querying 'all' fields with WP_User_Query.
Allow passing stdClass or WP_User to the WP_User constructor.

fixes #22057

This ticket was mentioned in Slack in #core by lindsaymac. View the logs.


4 years ago

Note: See TracTickets for help on using tickets.