Make WordPress Core

Opened 11 years ago

Closed 10 years ago

Last modified 8 years ago

#27026 closed defect (bug) (fixed)

wp_user_query order by meta_value not working when using role insider $args

Reported by: ecommy's profile ecommy Owned by: kovshenin's profile kovshenin
Milestone: 4.1 Priority: normal
Severity: normal Version: 3.8.1
Component: Users Keywords:
Focuses: Cc:

Description

Regarding:
https://core.trac.wordpress.org/ticket/21581

this code will not sort users using last name because of the role=subscriber inside args.

	$args = array( 
		'role' => 'Subscriber',
		'orderby' => 'meta_value',
        'order' => 'ASC',
        'meta_key ' => 'last_name',		
		'number' => $limit,
		'offset' => $offset
	);
	
	$wp_user_query = new WP_User_Query( $args );
	$users = $wp_user_query->get_results();

Change History (5)

#1 @TobiasBg
11 years ago

#27027 was marked as a duplicate.

#2 @TobiasBg
11 years ago

  • Component changed from General to Users

#3 @kovshenin
10 years ago

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

In 30094:

Use a nested meta query when querying by role in WP_User_Query.

If a user query includes a meta query together with a role argument,
nest the original meta query and append the role meta query with an
AND relationship.

fixes #23849, #27026.

#4 @kovshenin
10 years ago

  • Milestone changed from Awaiting Review to 4.1

#5 @boonebgorges
8 years ago

In 37359:

Tests: Correct 'meta_query' syntax in test related to WP_User_Query 'who' param.

The test, introduced in [32207], used the incorrect syntax for 'meta_query' -
one fewer level of array-nesting than what WP_Meta_Query requires. This
slip uncovered a bug introduced into WP_User_Query in [30094], whereby
an incorrectly formatted 'meta_query' parameter would be properly parsed by
WP_User_Query when passed alongside who=authors.

We need to fix the inconsistent syntax in order to resolve #36724.

See #36724, #32019, #23849, #27026.

Note: See TracTickets for help on using tickets.