Low search category groups as AND or OR
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
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.
Rob (Bluedreamer) 24 Mar 2015 14:31
Thanks Low, got it working now!