PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]
Botoscope is currently in early access

Support Forum

You need to log-in to create request (topic) to the support

Set OR logic for checkbox filters

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi, I'd like for multiple filters to display not only objects that have both characteristics, but at least one of them.
So, not AND logic, but OR logic. How can I set this in the filter widget or on the shortcode page?

For example, here https://cars.wp-filter.com/
I'd like to be able to select all those with climate control and all those with ABS, not just those with both. Would that be feasible? If so, how?

Thanks.
Bye

Hello

First of all, could you clarify: are"climate control" and"ABS" values of the same taxonomy (one filter with multiple checkboxes), or are they two separate filters/taxonomies?

If they are values of the same taxonomy, then selecting multiple checkboxes already works as OR by default — the plugin passes all selected term IDs in one terms array with the IN operator, so it returns posts that have at least one of the selected values.

If they are two different taxonomies, then OR logic between separate filters is not supported natively in the plugin at this time.

For example, here https://cars.wp-filter.com/ - here is logic AND works by default, just create filter sections and use. By the way all demo sites can be downloaded here https://wp-filter.com/demo-sites/

Hi,
First of all, thanks for the reply.
It doesn't seem to work the way you say, or maybe I'm not understanding correctly.
Using the demo site here https://cars.wp-filter.com/
In the filter block on the right, there's"Equipment" with the various boxes.
Among the boxes, you can see the"central locking (23)" option and the"abs+esp(15)" option, so two options from the same taxonomy, correct?
If you now select"central locking," you'll only see 23 cars, okay?
If you also add"abs+esp," which is 15, you should see 38 cars (so 38 results) if it were with the OR logic. Instead, the result is 20 cars, only those with both central locking and abs+esp. You can also see this simply by the reduced pagination.
So, can I see all the results for both selections?
Thanks for your help.

Hello

Sorry for the confusion in my previous answer, I need to correct myself.

In the first reply it was describing how the plugin behaves with taxonomies (categories, tags, custom taxonomy terms). When you select multiple terms of the same taxonomy, the plugin does combine them with OR logic by default, that part is correct.

However, after looking closer at the demo site you mentioned, I see that the Equipment block (Central locking, ABS+EPS, Climatisation, etc.) is not built from a taxonomy at all. Each of these items is set up as a separate meta field, with its own individual meta key. I am attaching screenshots showing this from the filter section settings, you can see each item has its own Item Type set to checkbox and its own unique Item meta key.

This is an important difference, because meta fields work differently from taxonomies. When you select several meta field checkboxes, each one becomes its own separate condition, and by default these conditions are combined with AND logic, not OR. That is why selecting both Central locking and ABS+EPS returns only the cars that have both attributes at the same time (the intersection), instead of all cars that have either one (the union). The number you get is smaller because it only counts cars matching both conditions together.

So to summarize: taxonomies combine with OR by default, but meta fields combine with AND by default. Since your Equipment filter is built with meta fields, that is why you are seeing AND behavior there.

Let me check on our side what options exist to switch this specific filter section to OR behavior, and I will follow up with you.

Thank you for the clarification. It would be very helpful to have a way to filter metadata with or. We're waiting for a possible solution. Thanks for the reply and congratulations on the entire plugin.

Hello

I can confirm there is a way to get OR logic for this filter form, and we want to set it up in a way that will keep working even after future plugin updates.

Open the file located at: wp-content/plugins/meta-data-filter/views/shortcode/do_mdf_search_form.php

Find these two lines near the top of the file:

$meta_data_filter_bool = 'AND';
$mdf_tax_bool = 'AND';

Replace them with:

$meta_data_filter_bool = apply_filters('mdf_meta_data_filter_bool', 'AND', $shortcode_id);
$mdf_tax_bool = apply_filters('mdf_tax_bool', 'AND', $shortcode_id);

Save the file. By itself this does not change anything yet, the default is still AND.

Now, in your theme's functions.php (or a code snippets plugin), add:

add_filter('mdf_meta_data_filter_bool', function($bool, $shortcode_id) {
    if ($shortcode_id == 179) {
        return 'OR';
    }
    return $bool;
}, 10, 2);

This will switch the Equipment filter section to OR logic, so selecting Central locking and ABS+EPS will show cars that have either one, not only cars that have both. Since the condition checks the shortcode id, other filter forms on your site will keep working with AND as before.

The advantage of doing it this way is that we are adding this exact same hook to the plugin core in an upcoming update. Once you update the plugin, the file will already contain these apply_filters lines, your functions.php code will keep working without any changes, and you will not need to touch plugin files again after that.

Try it ...

You are Welcome!