Hello how are you?
I created a users view, with a search field, and I would like this search to make a query in several custom fields at the same time (ex: name, city, neighborhood) using LIKE and all fields are STRING.
I configured the query filters, all right, however, I can't change from AND to OR, so that the search works correctly.
can you help me?
I'm waiting
thanks
Hi,
Thank you for contacting us and I'd be happy to assist.
To suggest the best way to achieve this, I'll need to see how this view is set up in the admin area.
Can you please share temporary admin login details, along with the link to the page with this view?
Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.
regards,
Waqar
Thank you for sharing these details.
To change the relations operator between the multiple custom fields filter to "OR", you can use the "wpv_filter_query" filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
For example:
add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
// process if specific view
if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 1234) ) {
if( !empty($query_args['meta_query']) ) {
$query_args['meta_query']['relation'] = 'OR';
}
}
return $query_args;
}
Note: Please replace '1234' with the actual ID of your target view.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
ok, I got it...
but what happens? does it have to be through code? don't have this native option in the visual filter selector?
thanks
Thanks for writing back.
We have an internal ticket to bring back the visual operator selection, for cases, where multiple custom field filters are involved.
I'm afraid, it won't be possible to share any time estimate, so for now, you can override it only using the code.