[wp-trac] [WordPress Trac] #32372: WP_User_Query fails on search_columns AND relation
WordPress Trac
noreply at wordpress.org
Thu May 14 14:18:25 UTC 2015
#32372: WP_User_Query fails on search_columns AND relation
--------------------------+------------------------------
Reporter: tareq1988 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by nikolov.tmw):
The problem I see here is that it will be potentially difficult to
separate out the search condition from other conditions.
For example I added the `include` query parameter and set it to `array( 2
)`. This is the resulting query:
{{{
WHERE 1=1 AND (
(
(
( wp_usermeta.meta_key = 'first_name' AND
CAST(wp_usermeta.meta_value AS CHAR) LIKE '%John%' )
OR
( wp_usermeta.meta_key = 'last_name' AND CAST(wp_usermeta.meta_value
AS CHAR) LIKE '%John%' )
OR
( wp_usermeta.meta_key = 'description' AND
CAST(wp_usermeta.meta_value AS CHAR) LIKE '%John%' )
)
AND
( mt1.meta_key = 'wp_capabilities' AND CAST(mt1.meta_value AS CHAR)
LIKE '%\"administrator\"%' )
)
) OR (user_login LIKE '%John%' OR user_nicename LIKE '%John%') AND
wp_users.ID IN (2)
}}}
This returned the user with ID 1, because of the `OR` clause in between
the other two clauses, effectively rendering the last clause useless( `AND
wp_users.ID IN (2)` ).
Also as you can see I added the `role` parameter and that added one more
clause to the meta query search.
Setting `'include' => array( 1 ), 'role' => 'subscriber'` also returned
the user with ID 1 - which is not correct(since they are an admin).
I don't have a good idea on how to separate things out and make the search
part use `OR` without breaking other things :(
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32372#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list