3

So I am trying to set up a faceted search which is based on categories - but EE's default category parameters aren't clever enough for me with just the & or | separators, so I was wondering if I could do what I need to with Low Search.

I have 5 category groups: Age, Artists, Type, Medium and Topic. In each of these is an unknown number of categories. I am displaying checkboxes on the front end for each category group, and have entries assigned to at least 1 category in each group. Here is my list of filters so you can see the options:

enter image description here

The default view when nothing is ticked is all entries. If I tick 'Multiple' I want all entries categorised with 'Multiple' to show. When I have 'Multiple' and '8-10' ticked I would like everything categorised as both 'Multiple' and '8-10' to show. So far so easy - but here is where EE's default breaks:

I tick 'Multiple', '8-10' and '11-14' I want to show everything that is categorised as 'Multiple' and '8-10' or 'Multiple' and '11-14'.

I hope this makes sense and isn't too long winded - ask if something isn't clear and I'll try to clarify. Does anyone know if this is possible with Low Search, and if not - how might I go about it?

Thanks!

3

Yep, that would be a job for the Categories filter.

For each group of categories, use a category:group_name parameter name to combine AND and OR matching. For example:

{exp:channel:categories category_group="1" style="linear"}
  <label>
    <input type="checkbox" name="category:group1[]" value="{category_id}"
    {if category_id IN ({low_search_category:group1})} checked="checked"{/if} />
    {category_name}
  </label>
{/exp:channel:categories}

{exp:channel:categories category_group="2" style="linear"}
  <label>
    <input type="checkbox" name="category:group2[]" value="{category_id}"
    {if category_id IN ({low_search_category:group2})} checked="checked"{/if} />
    {category_name}
  </label>
{/exp:channel:categories}

...

And repeat for each other category group. Note: this code should be put inside the Form tag.

| improve this answer | |
  • Thanks Low, this works really well as far as I can tell so far! I have it working with the user physically submitting the form themselves, however in its first iteration (using EE native categories) I had it working with Ajax. Form is on a page - results as an embed on that page. Ajax submits the categories to the embed when user clicks a checkbox and results update after each checkbox click. Do you know if this is possible to achieve with Low Search? Thanks again. – Joe Beaver Mar 5 '14 at 14:54
  • Hi again Low, don't worry about the Ajax thing. I found your Gist here gist.github.com/low/4632695 which explains how to do it nicely. Thanks! – Joe Beaver Mar 5 '14 at 15:39
0

If hitting "Unexpected ‘IN’ (VARIABLE); expected RD in Template" error in EE 2.9.2 try swapping conditional from

{if category_id IN ({low_search_category:group2})} checked="checked"{/if} />

to

{if category_id ~ '/(^|\|)'.low_search_category:group2.'($|\|)/'} checked="checked" {/if}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.