I have created a search form which allows user to search multiple categories groups and multiple categories within those groups.
So I have
Type
[] Category 1
[x] Category 2
[] Category 3
...
Location
[] Category 1
[x] Category 2
[] Category 3
[] Category 4
I've chosen to use slugs as the search parameter for usability purposes but that means that I have to get the element of each slug and then pass it into the entries query. Long story short,lots of queries to my database before I even get started outputting the categories above.
I'm interested in caching the category queries and I'm doing as follows
{% cache using key "restaurant-filter-type" %}
{% set typeList = craft.categories.group('restaurantType') %}
{% for type in typeList %}
<div class="field field--checkbox">
<input type="checkbox" name="type[]" id="{{ type.slug }}" value="{{ type.slug }}">
<label for="{{ type.slug }}">{{ type.title }}</label>
</div>
{% endfor %}
{% endcache %}
The problem I run into is when the user submits the form and the checked form elements arent being persistent because of the caching I've set.
I've tried looking at this SE question to help but the stumbling block for this is that there is the possibility that the parameter holding my restaurant type slugs may hold multiple values, hence the name="type[]"
. A simple replace
filter doesn't look likely to work in that situation.
Would anyone have any ideas how I could get around this?