Skip Navigation

[Resolved] Customizing the search

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to filter view by custom field values using "OR" logic?

Solution:

You can use "IN" Comparison function in custom field filter, for example:

Year is a string in URL_PARAM(wpv-wpcf-year)

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/

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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by camila 2 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#2362885
Screen Shot 2022-05-13 at 2.55.20 PM.png
Screen Shot 2022-05-13 at 2.54.21 PM.png

Tell us what you are trying to do?

Hi there. We need to revisit this ticket: https://toolset.com/forums/topic/help-with-search-modifications/

The solution isn't actually working. Actually it makes no difference whether the code is in place or if I comment it out.

The site is efao.ca, specific page is hidden link (its a document library)

If you open up the research section you will see there are various filters.

Currently if you select, for example: Year 2019 you will get results, and Year 2018 you will get results, but if you select years 2018 and 2019 you will get no results. Its looking for documents with both of those tags (AND). What we need is for either of those tags (OR).

In the previous ticket we were provided with the solution from here: https://toolset.com/errata/not-possible-to-compare-multiple-custom-field-filters-with-or-instead-of-and/

Either we though it was working and it wasn't, or it has stopped working. As mentioned, it doesn't make a difference to the results whether we have the code in place or not.

Thank you

#2362915
Desired Results.png
Screen Shot 2022-05-13 at 3.14.54 PM.png

actually I just realized what the code is doing.

If you look at my attached screenshot you'll see our Search section has 4 Custom fields (Language, Year, Document Type, Research Category).

The default behaviour is for example, you have something selected under Year, and something selected under Document Type, you will only get results that match both of those criteria. (In my example, documents have to 2018 AND Research Summary)

The custom code changes that to an OR, so in my example I get document that have 2018 OR are Research Summary Documents.

In this particular case, the default is actually ok.(AND)

What we are looking for is if there are multiple options selected in a custom field for those to be OR.

So for example If I have 2018 and 2019 selected under Year, and Research Summary under documents, we would like the results to contain : documents properties (2018 or 2019) AND Research Summary.

Basically OR within the different properties of a custom field.

How can we achieve this?

Thank you

#2364163

Hello,

The credentials you provided in previous thread is removed:
https://toolset.com/forums/topic/help-with-search-modifications/#post-2352551

since it is a custom codes issue, please provide your website credentials in below private message box, I need to test and debug it in a live website, thanks

#2364829

Thanks for the details, I have done below modifications in your website:
Edit the post view "Research Library List":
hidden link
In section "Query Filter", change the "Year" field filter from:
Year is a string equal to URL_PARAM(wpv-wpcf-year)

To:
Year is a string in URL_PARAM(wpv-wpcf-year)

Please test again, check if it is fixed.

More help:
https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/
IN
A list of values Checks if the custom field value is within the list of compare values

#2366049

My issue is resolved now. Thank you!