I am trying to write a user search query, i have location and searching keyword (user name)
i need to search all user, with last name or first name matches to searching keyword for a
specified loaction
my code here,
$args = array(
'meta_query' => array(
'relation' => 'AND',
0 => array(
'key' => 'last_name',
'value' => $search_string,
'compare' => 'LIKE'
),
1 => array(
'key' => 'first_name',
'value' => $search_string,
'compare' => 'LIKE'
),
2 => array(
'key' => 'user_city',
'value' => $Location,
'compare' => 'LIKE'
),
),
);
$users = new WP_User_Query( $args);
$users = $users->get_results();
but i want ‘relation’ OR for first name and last name and relation AND for location, how i can do it ?
please use
I believe it’s not possible to have multiple relation fields in a wp_query. Please reference https://codex.wordpress.org/Class_Reference/WP_User_Query.
As an alternative, you can look into pre_user_query, which is a hook to call a function before the query is called.
Try this