AND / OR functionality
-
I have hundreds of taxonomies and am seeing and issue on my end.
I have taxonomy group of Service 1, Service 2, Service 3 and then another group Gold, Silver, Bronze – If I select Service 2 and Bronze, It should filter all posts with those two common taxonomies selected. However, on my end – If I select Service 2, and Silver – it shows other Silver, and other Gold, Bronze taxonomies. I have “AND” selected on all my widget filters. Is there something I am doing wrong on my end or is it a bug? thank you again!!!!!!!
-
Hi @jomo5280,
Could you please double check that under each taxonomy group > advanced, the group relation is set to “AND” then the “parent logic”, under “parent option” is also set to “AND”?
When configured this way, the resulting query should look something like this:
[tax_query] => Array ( [relation] => AND --This would come from the parent option [0] => Array ( [relation] => AND --This would come from the group relation option [0] => Array ( [taxonomy] => category [field] => id [terms] => 1 [include_children] => 1 ) [1] => Array ( [taxonomy] => category [field] => id [terms] => 169 [include_children] => 1 ) [2] => Array ( [taxonomy] => category [field] => id [terms] => 14259 [include_children] => 1 ) ) [1] => Array ( [relation] => AND --This would come from the group relation option [0] => Array ( [taxonomy] => post_tag [field] => id [terms] => 171 [include_children] => 1 ) [1] => Array ( [taxonomy] => post_tag [field] => id [terms] => 14260 [include_children] => 1 ) ) )Also keep in mind: if you’re using separate filter widgets on the same page (all targeting the same post widget), their selections will be combined in the final query. So multiple active filters will apply cumulatively.
If you’re still seeing unexpected results, feel free to reach out to me directly at [email protected]. I’d need to enable the debug log on your site to inspect the exact query being generated.
Thanks,
DaraI’m seeing a similar issue with the filter widget on my site. Setting the Parent Logic field to AND on the filter widget is not working as described in the documentation.
I have two filters added to the widget, both taxonomy data sources (category and tag). I want the filter to work so that when I select category1 and also tag1 and tag2 it will show me only those posts in category1 with either tag1 or tag2. however it is also returning any post for any of the other categories that also have tag1 or tag2, even though the Parent Logic option is set to AND.Is this a bug or have I misconfigured?
Hi @wheeldj,
Thanks for the report. The Parent Logic setting is responsible for the relationship between AND/OR groups, which I realize might not be what most users expect. To address this, I’ve added a new control in the next version that will let users decide the relation between OR groups.
Right now, your query would look something like this:
( [order] => ASC [orderby] => date [post_type] => post [paged] => 1 [tax_query] => Array ( [relation] => AND // Parent Logic [0] => Array ( [relation] => OR // Concatenated OR Group Logic [0] => Array ( [taxonomy] => category [field] => id [terms] => Array(14259, 14262) [include_children] => 1 ) [1] => Array ( [taxonomy] => post_tag [field] => id [terms] => Array(171, 14260) [include_children] => 1 ) ) ) )In the meantime, you can try setting the group logic on your post categories to AND so it splits the groups, or as a workaround, you can comment out the line 330 of the class-jax.php file.
// $args[‘tax_query’][] = array_merge( [ ‘relation’ => ‘OR’ ], $query_or );
If you run into any other issues or need further assistance, please let me know.
Regards,
DaraThanks Dara – You’re right that’s not what I would have expected, but good to know. Thanks for the super speedy answer!
Do you have a rough idea when the new version will be available? (I’m not a web coder so trying to figure out whether it’s worth me hacking around in the files or just waiting for the next release!!)
Thanks again!
Jamie.Hi Jamie,
I would expect the new release to be ready later this week. I’m currently testing all the most recent changes to make sure everything is stable before pushing it live.
If you’re not in a rush, I’d recommend holding off rather than modifying the file manually, especially since the upcoming version already addresses the issue you ran into. But if you need a quick workaround in the meantime, feel free to let me know and I’ll guide you through it.
Thanks again for your patience!
Regards,
DaraJust confirming that this issue should now be resolved in v1.5.0. The update introduces a cleaner tax_query structure and follow more closely the parent logic.
I’ll go ahead and mark this thread as resolved, but feel free to reopen or start a new one if you run into anything else.
Thanks again for your feedbacks.
Best,
Dara
The topic ‘AND / OR functionality’ is closed to new replies.