Opened 11 years ago
Closed 11 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: |
Description
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', array( 'key' => 'first_name', 'value' => 'alex', 'compare' => 'LIKE'), array( '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)
Note: See
TracTickets for help on using
tickets.
sorry I mean it will return all users not only 'editor'.
thanks.