Support Forum

Content of the article

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

Multiple 'or' with 'and' conditions

(new from 01-07-2019)
This support system is for all types of the plugins as for premium versions, so for free ones! If you have premium version do not forget in the private data of the request (!!not in the text of the support request!!) after its publishing insert purchase code please (see green button on the right side) and press Save button.
If you not got email within 24 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 there.

We have this plugin and we got a request from client to change the filter conditions. How we can set 2 attributes in a group with a 'or' condition? For example, (HLA-A-Primary 1 'or' HLA-A-Primary 2) 'and' (HLA-A-Secondary 1 'or' HLA-A-Secondary 2). Is it possible with below code, which seems to be not working as expected? Basically, we need to group 2 attributes with or condition with another group with a 'and' condition. Please advice

add_filter('woof_main_query_tax_relations', 'my_woof_main_query_tax_relations');

function my_woof_main_query_tax_relations()
{
return array(
'pa_hla-a-p-1' => 'OR',
'pa_hla-a-p-2' => 'AND',
'pa_hla-a-s-1' => 'OR',
'pa_hla-a-s-2' => 'AND'
);
}

With regards,

Ravi Kumar

Hello Ravi Kumar

The logic of comparison between different attributes is AND.  Unfortunately, this plugin cannot change this behavior.

You need customization of the code. You can change the comparison logic in a search query using standard hooks  OR - https://products-filter.com/hook/woof_get_tax_query/

Thanks for the reply.

However, if I use the below code, I see no changes. In this case, the filter should look into the value in all 4 attributes right?

add_filter('woof_main_query_tax_relations', 'my_woof_main_query_tax_relations');

function my_woof_main_query_tax_relations()
{
    return array(
    'pa_hla-a-p-1' => 'OR',
    'pa_hla-a-p-2' => 'OR',
    'pa_hla-a-s-1' => 'OR',
    'pa_hla-a-s-2' => 'OR'
    );
}

Thanks!

Ravi

Thanks for the reply.

However, if I use the below code, I see no changes. In this case, the filter should look into the value in all 4 attributes right?

add_filter('woof_main_query_tax_relations', 'my_woof_main_query_tax_relations');

function my_woof_main_query_tax_relations()
{
    return array(
    'pa_hla-a-p-1' => 'OR',
    'pa_hla-a-p-2' => 'OR',
    'pa_hla-a-s-1' => 'OR',
    'pa_hla-a-s-2' => 'OR'
    );
}

#Even I tried with the below code which also not working as explained above:

add_filter('woof_get_tax_query', 'my_woof_get_tax_query');

function my_woof_get_tax_query($tax_args){

    //do smth here

    $tax_args =  array(

        'pa_hla-a-p-1' => 'OR',

        'pa_hla-a-p-2' => 'OR',

        'pa_hla-a-s-1' => 'OR',

        'pa_hla-a-s-2' => 'OR'

        );

    return $tax_args;

}

Thanks!

Ravi

Hello Ravi

Yes, your code does not make sense.

You change the logic inside the attribute. But for attributes, the default logic is OR

So  you change  OR  to  OR