WordPress.org

Make WordPress Core

Opened 20 months ago

Closed 7 months ago

Last modified 7 months ago

#21581 closed enhancement (fixed)

Add orderby meta_value to WP_User_Query

Reported by: wpsmith Owned by: wonderboymusic
Milestone: 3.7 Priority: normal
Severity: normal Version:
Component: Users Keywords: has-patch
Focuses: Cc:

Description

For some reason, we cannot easily order the WP_User_Query() by last_name without directly editing the SQL statements. However, there is an easy way to add this that would work parallel to WP_Query().

// prepare arguments
$args  = array(
	'orderby' => 'meta_value',
	'meta_key' => 'last_name',
);
$user_query = new WP_User_Query( $args );

Attachments (1)

21581_user.patch (448 bytes) - added by wpsmith 20 months ago.

Download all attachments as: .zip

Change History (10)

wpsmith20 months ago

comment:2 avryl8 months ago

  • Component changed from General to Query

comment:3 wonderboymusic8 months ago

  • Keywords 2nd-opinion dev-feedback removed
  • Milestone changed from Awaiting Review to 3.7

Makes sense, patch still applies

comment:4 hotchkissconsulting8 months ago

Tested with latest trunk, patch works

comment:6 c3mdigital8 months ago

#17179 was marked as a duplicate.

comment:7 SergeyBiryukov8 months ago

  • Component changed from Query to Users

Related: #23045

comment:8 wonderboymusic7 months ago

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

In 25331:

Support orderby => meta_value in WP_User_Query. Adds unit test.

Props wpsmith.
Fixes #21581.

comment:9 ocean907 months ago

  • Type changed from defect (bug) to enhancement
Note: See TracTickets for help on using tickets.