Skip Navigation

[Resolved] Filter with custom field checkboxes that compare using OR instead of AND in view

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

Problem: I have a View that includes front-end filters for a checkboxes group custom field. I would like to filter the results with "OR" instead of "AND", so that results with any matching checkboxes selected will be displayed.

Solution: Use the Query Filter editor to choose the comparison "in" instead of "equal to". If you cannot see the Query Filter panel, activate it in the Screen Options tab.

This support ticket is created 6 years 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by katrina 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1139099

Tell us what you are trying to do? display results of filtering custom fields using OR parameter

Is there any documentation that you are following? No

Is there a similar example that we can see? No

What is the link to your site? Can provide privately

I have several custom fields in a post, and want to create a view with filters that the user can view results where the post has either of several results selected in a checkbox group. I am only able to get it to compare using AND, and there doesn't seem to be an OR option.

For example, I want to see all "students" who are EITHER "unenrolled" course ABC or only "partially completed" the same course. Currently results are often NILL because it's impossible that any student can be BOTH.

I cannot use taxonomies instead, because other custom fields are conditional upon the selection on the back end.

Is this possible?

(I can provide private a link to a password protected page with an example in a private message)

PS) I found a link to this support thread where I think the user had a similar issue, which makes me think its impossible, and the workaround suggested is beyond my skillset, so I am just wondering if there is now an easier option using the Toolset setup window? https://toolset.com/forums/topic/creating-a-multi-condition-andor-custom-filter-in-a-view/

#1139788
Screen Shot 2018-11-04 at 11.11.28 AM.png

Hi, after you insert your filter in the Search and Pagination section, you can modify the Query Filter for the checkboxes group custom field to use "in" instead of "equal to" (see the screenshot). If you cannot see the Query Filter panel, scroll to the top right corner of the screen and click "Screen Options" to expand the editor. You can turn the Query Filter panel on here.

#1139867
checkboxfilter.jpg

Hi Christian,

Thanks so much for your response. This seems promising, but I think I maybe did a poor job of explaining my problem.

The filter I need is on the front end for the user to use. I need for them to be able to filter results using checkboxes where the results can be either of two scenarios( 'OR') — not both ('AND').

For example, if this is the checkboxes on the front end where the use has two options selected like this:

[ ✓ ] prospective students
[      ] newly enrolled students
[ ✓ ] students who have partially completed the course
[      ] students who have fully completed the course and graduated

I want the results to show both sets of people, both the prospective students and those who have partially completed the course. However, at the moment, the results in the above example would always produce zero reults, because it's impossible for a student to be both a prospective student and have also partially completed the course.

Attached is an image that shows the options I have available to me when I add the checkbox filter to the page.

Is what I want possible?

#1140568

I need for them to be able to filter results using checkboxes where the results can be either of two scenarios( 'OR') — not both ('AND').
You explained it well, and that's exactly what happens when you choose "in" instead of "equal to" in the Query Filter. In your example, the "equal to" option filters results such that all the results shown have both "prospective" and "partially completed" checked. The "in" option will filter results such that all the results shown have either "prospective" or "partially completed" checked. Your screenshot shows the popup dialog for adding the checkboxes in the Search and Pagination editor. However, the "in" option isn't available in this popup, it's only available in the Query Filter editor area. So you can choose "equal to" when inserting the filter in the Search and Pagination editor, then scroll up to the Query Filter area and tweak the checkbox filter comparison to be "in" instead of "equal to".

#1140586

Hi Christian ,

Thanks so much for persisting with me!

In that case, I think the problem I am having is that there is no Query Filter area when I scroll up within this View, and there doesn't seem to be a way for me to add one.

(I am used to using the Query Filter area when creating other types of view, but it's not available in this View.)

Would you like for me to provide access to take a look?

Katrina

#1140711

If you cannot see the Query Filter panel, scroll to the top right corner of the screen and click "Screen Options" to expand the tab. You can turn the Query Filter panel on here.

#1140714

Woah - thank you! The clouds have parted and now all makes more sense finally. Your solution works. Thank you so much, I really appreciate it!