WP_User_Query ignoring ‘meta_query’ arguments

But once I try to look for other meta values, the return bring all members in the DB.

Are you sure the meta other than name did not work, i.e. all members/users were returned?

Because as I could see it, for your keywords, country and disciplines meta, so long as your compare value is good, then the meta query would work and only members having the specified metadata that would be returned.

For example, your compare for the keywords meta is LIKE, so if you searched for foo and there were members with foo (regardless of the letter case) in their keywords meta, then only those members would appear in the user query’s results.

So make sure your compare value is good, particularly for the disciplines meta which I supposed contains multiple values that are separated using a comma (e.g. discipline 1, discipline 2) and yet, your compare is = which means an exact-match search that’s commonly used for meta values with a single value.

Now as for the first/last name search, I noticed the following issues:

  1. Your meta query clauses are missing key (meta key/name) and value (meta value), and WordPress ignored the meta query because the meta key is not specified. Also, search and search_columns are not valid keys for clauses in a meta query.

  2. The array( 'relation' => 'OR', $searchName ) produces array( 'relation' => 'OR', array( 'search' => ..., ..., ..., array( ... ) ) ) instead of array( 'relation' => 'OR', array( ... ), array( ... ) ), so your meta query wouldn’t work properly even if you specified the correct meta key.

  3. You should use $searchName[] = array( to add the first_name array, like you did with the last_name array.

So, try defining the $searchName like this:

$searchName = array(
    'relation' => 'OR',
);

$searchName[] = array(
    'key'     => 'first_name', // meta key
    'value'   => $name,        // meta value
    'compare' => 'LIKE'
);

$searchName[] = array(
    'key'     => 'last_name', // meta key
    'value'   => $name,       // meta value
    'compare' => 'LIKE'
);

And then in $args, add meta_query like so:

'meta_query' => array(
    'relation' => 'AND',
    $searchName,
    $searchKeywords,
    $searchCountry,
    $searchDiscipline
)