Filter entries by multiple categories I am trying to set up a form with checkboxes that allows users to filter entries by selecting multiple categories, but I am not quite getting it right.

Currently this is my form:

{% set subcategoryParam = craft.request.getParam('subcategory') %}
{% set subcategories = craft.categories.group('partnerAreas').find() %}

&lt;form action="{{ craft.request.url }}"&gt;

  {% for subcategory in subcategories %}
    &lt;input type="checkbox" value="{{ subcategory.slug }}" id="{{ subcategory.slug }}" name="subcategory" {{ subcategory.slug in subcategoryParam ? 'checked'}}&gt;
    &lt;label class="label__checkbox" for="{{ subcategory.slug }}"&gt;
      {{ subcategory.title }}
    &lt;/label&gt;
  {% endfor %}

  &lt;button type="submit"&gt;
    Search
  &lt;/button&gt;
&lt;/form&gt;


Submitting this form gets me URL query strings like this:

?subcategory=sourcing-local-products&amp;subcategory=communication

When I am using craft.request.getParam('subcategory'), only the last selected subcategory gets picked up (as you would expect).

I've tried setting the name on the checkbox field to subcategory[], but that gets me an array to string conversion template error and the URL query string then looks like this:

?subcategory%5B%5D=sourcing-local-products&amp;subcategory%5B%5D=communication

What do I need to do to get a comma separated list for the subcategory parameter like this:

?subcategory=sourcing-local-products,communication

And once that is working, how do I then get all the entries that have any of the selected categories assigned via a Matrix field?

This is what I've currently got:

{% set subcategoryParam = craft.request.getParam('subcategory') %}
{% set selectedSubcategories = craft.categories.slug(subcategoryParam) %}
{% set entries = craft.entries({
  section: listingType,
  relatedTo: {
    targetElement: selectedSubcategories,
    field: 'involvementAreas.area'
  }
}) %}


But I imagine that's not quite right if I want to account for an array of selected categories...
I had to get this working just the other day. Here is what I did:

{# Get the relevant entries #}
{% set categoryQuery = craft.request.getParam('category') %}
{% set categories = craft.categories.group('sectionName').slug(categoryQuery) %}

{# Set the search parameters #} 
{% set searchParams = {
    relatedTo: categories,
    section: 'sectionName'
} %}

{# Get the relevant entries #}
{% set relevantEntries = craft.entries(searchParams) %}


In the form I have:

&lt;form action=""&gt;

{% for category in craft.categories.group('services') %}
    &lt;input id="{{category.slug}}" type="checkbox" name="category[]"  value="{{ category.slug }}" {{ category.slug in categoryQuery or categoryQuery == null  ? 'checked'}}&gt;
    &lt;label for="{{ category.slug }}" &gt;{{ category.title }}&lt;/label&gt;
{% endfor %}

&lt;/form&gt;


This seems to work for me.