WP_User_Query search seems bugged
-
Hi,
I’m trying to create a user search query, which would search by all user colums (login, nicename, email, url) and by metadata.
This is my code:$args = array( 'fields' => 'all_with_meta', 'search' => '*'.$search_string.'*', 'search_columns' => array( 'user_login', 'user_nicename', 'user_email', 'user_url', ), 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'first_name', 'value' => $search_string, 'compare' => 'LIKE' ), array( 'key' => 'last_name', 'value' => $search_string, 'compare' => 'LIKE' ), ), ); $user_query = new WP_User_Query( $args );
And it seems like search_columns are ignored, and this is the resulting query:
[query_fields] => DISTINCT SQL_CALC_FOUND_ROWS wp_users.* [query_from] => FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) [query_where] => WHERE 1=1 AND ( ( wp_usermeta.meta_key = 'first_name' AND CAST(wp_usermeta.meta_value AS CHAR) LIKE '%parent%' ) OR ( wp_usermeta.meta_key = 'last_name' AND CAST(wp_usermeta.meta_value AS CHAR) LIKE '%parent%' ) ) AND (display_name LIKE 'parent') [query_orderby] => ORDER BY user_login ASC [query_limit] =>
So basically search is summed up to this, every time:
AND (display_name LIKE ‘parent’)Whereas I would expect it to be:
OR (user_login LIKE 'parent') OR (user_nicename LIKE 'parent') OR (user_email LIKE 'parent') OR (user_url LIKE 'parent')
Any ideas?
Thanks!
- The topic ‘WP_User_Query search seems bugged’ is closed to new replies.