0

I'm running this code:

$users = new WP_User_Query( 
array(      
    'search'     => '*63.19-4-00*',
    'meta_query' => array(
        'relation' => 'OR',
        array('key' => 'field_1', 'value' => '63.19-4-00', 'compare' => 'LIKE'), 
        array('key' => 'field_2', 'value' => '63.19-4-00', 'compare' => 'LIKE')
    )
));

This query don't return my user. If i get the SQL Request, Wordpress are generating this:

SELECT DISTINCT SQL_CALC_FOUND_ROWS wpms_users.* FROM wpms_users INNER JOIN wpms_usermeta ON ( wpms_users.ID = wpms_usermeta.user_id ) WHERE 1=1 AND ( ( wpms_usermeta.meta_key = 'field_1' AND wpms_usermeta.meta_value LIKE '%63.19-4-00%' ) OR ( wpms_usermeta.meta_key = 'field_2' AND wpms_usermeta.meta_value LIKE '%63.19-4-00%' ) ) AND (user_login LIKE '%63.19-4-00%' OR user_url LIKE '%63.19-4-00%' OR user_email LIKE '%63.19-4-00%' OR user_nicename LIKE '%63.19-4-00%' OR display_name LIKE '%63.19-4-00%') ORDER BY user_login ASC 

If i get this SQL and run on my phpmyAdmin changing

...63.19-4-00%' ) ) AND (user_login..

to

..63.19-4-00%' ) ) OR (user_login..

this works. Why?

If i remove all this sequence above this works too.

AND (user_login LIKE '%63.19-4-00%' OR user_url LIKE '%63.19-4-00%' OR user_email LIKE '%63.19-4-00%' OR user_nicename LIKE '%63.19-4-00%' OR display_name LIKE '%63.19-4-00%')
  • Maybe try rebuilding your query and passing value into each sub-array instead of search in the outer array? codex.wordpress.org/Class_Reference/… – WebElaine Sep 25 '17 at 17:41
  • 1
    lol.. how stupid I'am haha.. It's this! Remove 'search' parameter and work's like a charm! – Lincoln Lemos Sep 25 '17 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.