Skip Navigation

[Resolved] Help with Search Modifications

This support ticket is created 2 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by camila 2 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#2351761

Hello,
I have the following site with Toolset and a Library Search functionality: hidden link
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

#2351801

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

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

#2351837

Hi Shane, we are not sure how to implement the solution. Should we just paste that code in the functions.php file?

#2351971

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

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

#2351997

Hi Shane, thanks. i added the code and changed the id and it's not working

#2352027

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

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

#2352611

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

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

#2352691

My issue is resolved now. Thank you!