Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#25421 closed defect (bug) (duplicate)

`get_users`, role parameter conflict with multiple meta_query and OR relation

Reported by: takien Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6.1
Component: Users Keywords: needs-patch
Focuses: Cc:


affected function/class: WP_User_Query or get_users

role parameter when it combined with meta_query, it will produce unexpected result.

PROBLEM/EXAMPLE: it's impossible to make query user with role 'editor' which has last_name 'alex' OR first_name 'alex'

$args = Array(
   'role'  => 'editor',
   'meta_query' => Array(
       'relation' => 'OR',
	'key'     => 'first_name',
	'value'   => 'alex',
	'compare' => 'LIKE'),
         'key'     => 'last_name',
         'value'   => 'alex',
         'compare' => 'LIKE')

query debug:

WHERE 1=1 AND ( (wp_usermeta.meta_key = 'first_name' AND CAST(wp_usermeta.meta_value AS CHAR) LIKE '%alex%')
OR  (mt1.meta_key = 'last_name' AND CAST(mt1.meta_value AS CHAR) LIKE '%alex%')
OR  (mt2.meta_key = 'wp_capabilities' AND CAST(mt2.meta_value AS CHAR) LIKE '%\"editor\"%') )

it will simply return all 'editor'.

SOLUTION: role should use AND relation independently regardless the custom relation.

Change History (2)

#1 @takien
8 years ago

sorry I mean it will return all users not only 'editor'.

#2 @SergeyBiryukov
8 years ago

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

Duplicate of #23849.

Note: See TracTickets for help on using tickets.