Category as keyword searched?
I am working with Low Search and using the category filtering tool where users can select multiple categories, from multiple groups to display channel entries. The search form is working perfectly, however, we would like to display to the user which categories they selected and allow them to clear one, or more of them individually which would render different search results. Is this possible?
I have been referring to the docs here as a starting place: https://gotolow.com/addons/low-search... but I am currently unable to display the selected categories using the {low_search_category} parameter within the search results tag.
Replies
Low 1 May 2018 08:44
You can approach this in multiple ways.
First of all, you can use a search form where you have the selected categories highlighted (like in this example). Then it's just a matter of re-submitting the form to refine or broaden the search results. You can even automate this with JavaScript to submit the form on checkbox change. Be sure to set the query="" parameter on the Form tag, so it knows what was submitted.
Secondly, you could use the URL tag to compose a new search results URL and use the toggle:param parameter to remove a given parameter value.
Digital Designs 1 May 2018 16:57
Thank you for the direction. I have started working with the URL tag to compose a new search results URL but am having a little trouble. Here is my code:
{exp:low_search:form query="{segment_2}" search_mode="all" result_page="homes-search/%s"}
{exp:channel:categories category_group="7" style="linear"}
<div class="options">
<label>
<input type="checkbox" name="category:status[]" value="{category_id}"{if low_search_category:status ~ '/\b'.category_id.'\b/'} checked{/if}>
{category_name}
</label>
</div>
{/exp:channel:categories}
{exp:channel:categories category_group="6" style="linear"}
<div class="options">
<label>
<input type="checkbox" name="category:availability[]" value="{category_id}"{if low_search_category:availability ~ '/\b'.category_id.'\b/'} checked{/if}>
{category_name}
</label>
</div><!--end options-->
{/exp:channel:categories}
{if segment_2}
<a class="remove-filter" href="{low_search:url toggle:status="available|unavailable"}"><i class="fa fa-times-circle"></i>{low_search_category:status}</a>
{/if}
{/exp:low_search:form}
Digital Designs 1 May 2018 16:59
The form is working like the example where options remain checked and are visible, but additionally, I would also like to include an "active filters" section where users can click a link to remove their selection.
Low 1 May 2018 17:56
Inside the Form or Filters tag, you'd need to use the channel:categories tag along with its show="" parameter to limit the output to the selected categories. Then use the output of the channel:categories tag to generate the URL tags.
Something like this (untested):
Digital Designs 1 May 2018 18:01
Thank you! This worked perfectly.