Skip Navigation

[Resolved] "OR" Filtering on Archive Search

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 3 voices.

Last updated by Nigel 12 months ago.

Assisted by: Minesh.

Author
Posts
#2677665

I have an archive page here:

hidden link

with a search filter that allows to narrow down the search using 3 different taxonomies. Now, when the user selects more than one value within the same taxonomy or chooses 2 different taxonomies, the results are broadened, while I need it to be the other way round: it should be an "OR" instead of "AND".

How can I achieve that?

Thank you in advance!

#2677710

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You will have to use WordPress standard hook "pre_get_posts" in order to modify the archive query.

Please check the following related ticket that might help you:
- https://toolset.com/forums/topic/specify-and-condition-for-custom-search-filter-taxonomy-in-wordpress-archive/#post-1839755

#2677720

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Just to clarify what Minesh wrote, it is possible to modify the query to specify 'AND' instead of the default 'OR' using the pre_get_posts hook when it comes to applying filters for terms from different taxonomies (e.g. only show posts that have this colour AND that size), but it is not possible to modify the behaviour when filtering by terms from the same taxonomy (e.g. if you choose 'red' and 'blue' terms of a colour taxonomy, that will always be interpreted as show posts that are either red or blue).

That relates to how taxonomy queries behave in WordPress, it is not specific to Toolset. It may be possible to modify this behaviour by creating custom database queries, but that is outside the scope of support we can give, I'm afraid.

#2677722

Thanks to you both,
thank you for pointing me to the right direction and thank you for the explanation.

Apparently the code provided worked exactly as I hoped..!