All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Low search category groups as AND or OR

Rob (Bluedreamer) 20 Mar 2015 16:33 question, complete

Low

I've got a search form similar to this that pulls in various category groups, for example.


{exp:low_search:form result_page="search/results" query="{segment_3}" form_class="filter"}

{exp:channel:categories channel="works" category_group="1" show_empty="no" style="linear"}
<label for="c{category_id}"><input type="checkbox" id="c{category_id}" name="category[]" value="{category_id}"{if low_search_category ~ '/\b'.category_id.'\b/'} checked{/if}> <span>{category_name}</span></label>
{/exp:channel:categories}

{exp:channel:categories channel="works" category_group="2" show_empty="no" style="linear"}
<label for="c{category_id}"><input type="checkbox" id="c{category_id}" name="category[]" value="{category_id}"{if low_search_category ~ '/\b'.category_id.'\b/'} checked{/if}> <span>{category_name}</span></label>
{/exp:channel:categories}

<button type="submit">Show me</button>

{/exp:low_search:form}


I'm trying to get my head around how I can combine AND/OR for results, eg

Group1-cat1 OR Group1-cat3
AND
Group2-cat2 OR Group1-cat6

Any ideas?

Rob

Replies

  1. Low 20 Mar 2015 21:25

    Right now, in the two lists, you're using the same parameter name: category. That means that any (OR) of the selected categories in two lists will be applied to the search results.

    Important note: all parameters are combined with AND.

    So, if you want to combine AND and OR, you have to be creative in how you group your categories. Another important note: the groups don't need to reflect actual category groups per se, but it's usually the case, as it's easier to generate.

    The example you gave translates to:

    category:foo="1|3" category:bar="2|6"

    ...where "foo" and "bar" are arbitrary group names.

    Basically, the categories you want to combine with OR should belong to the same group. Different groups (or to be precise, different params) are combined with AND.

    Since you're using the channel:categories tag to generate a list of categories, they will most likely belong to the same parameter-group (eg. category:groupname). You'd probably need to hard-code categories if you want the result you're after.

  2. Rob (Bluedreamer) 24 Mar 2015 14:31

    Thanks Low, got it working now!

    peter e 11 Jul 2018 15:01

    I know this post is old but how did you resolve this issue?

    Rob (Bluedreamer) 11 Jul 2018 15:10

    It's been so long ago I can't even recall what site this was for.