Hello,
I have the following site with Toolset and a Library Search functionality: lien caché
I would like to add the following modifications, but nor sure how to do it:
1. If, for example, 2 years are selected (2019 & 2018, and 1 document type (Research protocol), desired results would be all research protocols from 2019 and 2018
basically : (2019 or 2018) AND Research protocol
2. Or another example
- If, for example, 2 years are selected (2019 & 2018, and 2 document type (Research protocol, Research report),
(2019 or 2018) AND (Research protocol OR Research report)
.. so basically all Research protocol and Research reports from 2019 and 2018.
Please let us know how can we implement these queries?
Thanks
Hi Camila,
Thank you for getting in touch.
The problem here is that we may not be able to get this logic working exactly as you would want it. Currently we can only do an AND across multiple custom fields.
Secondly to change the view Logic to an OR search won't be possible through the GUI as the option isn't there for it. However we are aware of the issue and have created an erratas page for this with a workaround at the link below.
https://toolset.com/errata/not-possible-to-compare-multiple-custom-field-filters-with-or-instead-of-and/
What you can do is to implement the solution below on your site and let me know if your search is now producing the desired results.
Thanks,
Shane
Hi Shane, we are not sure how to implement the solution. Should we just paste that code in the functions.php file?
Hi Camila,
That is correct or you can paste the code at Toolset -> Settings -> Custom Code and activate it.
Please change the ID 120 to the ID of the view that you want this code to apply to, in this case your view id is 199
Thanks,
Shane
Hi Shane, thanks. i added the code and changed the id and it's not working
Hi Camila,
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?
Please where applicable please provide me with a link to an example page where I can see the issue.
I've enabled the private fields for your next response.
Thanks,
Shane
Hi Camila,
I've made some modifications to the code. The final code is now.
/**
* Modify View custom field filters to use OR instead of AND
*/
function tssupp_filter_query_or($view_args, $view_settings, $view_id)
{
$view_ids = array( 199 ); // Edit. Array of View IDs to modify
if ( in_array($view_id, $view_ids) )
{
if ( !empty($_GET['wpv_view_count']) )
{
$view_args['meta_query']['relation'] = 'OR';
}
}
return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_filter_query_or', 101, 3);
It should now be working as intended.
Thanks,
Shane
My issue is resolved now. Thank you!