The name field is your default field in this plugin and it seems that it has an OR relation to my custom fields where the relation that I’m changing is only on my custom fields.
Example
// relation is OR
Name = ” Gender = ‘Male’ Status = ”
Result is mixed
// relation is AND
Name = ” Gender = ‘Male’ Status = ”
Result is OK
// relation is OR
Name = ‘Mary’ Gender = ‘Female’ Status = ”
Result is OK
// relation is AND
Name = ‘Mary’ Gender = ‘Female’ Status = ”
No result
I’m sorry, but searching by multiple meta fields is not supported “out of the box”. This type of complex user query probably needs a custom WP_User_Query, which can be achieved by filtering pre_get_users but is not covered under support.
I will note that SUL passes a query_id parameter equal to simple_user_listing by default (but can accept an even more custom ID via shortcode parameter). You can use this to apply your filter modifications strictly to your custom query and only your custom query.
function kia_custom_query( $query ) {
if ( isset( $query->query_vars['query_id'] ) && $query->query_vars['query_id'] == 'simple_user_listing' ) {
// do something to your user query
}
}
add_action( 'pre_user_query', 'kia_custom_query' );
Sorry but I don’t understand the function of your given code. Could it do what I need? I need to not include in the query the fields that does not have value like
Name = ‘Mary’ Gender = ‘Female’ Status = ”
?as=Mary&gender=Female&civil_status=
Since status has no value, it should be
?as=Mary&gender=Female
Anyway by the way I think I found an alternative. I just removed the default field and create my own for names. Is there a way that my field could find the string that contains it?
Or is there a value for wildcard?
The code does nothing, it is just an example of how you would need to filter pre_get_users…. which is what you need to do, though I don’t know what the exact parameters you need. To reiterate what I said in the other thread, if your meta search box has no value, do not add it to the query at all. That works better than trying to add it with a blank value or with a wild card. Good luck.
Thank you for the answer but I created another for that topic though.