{# Get search parameters from the URL query string #} {% set trainingQuery = craft.request.getParam('training') %} {# Start an array of search parameters (relationParam) with 'and' to match ALL categories #} {% set relationParam = ['and'] %} {# Find categories that match the slugs in your query string... #} {% for querySlug in trainingQuery %} {% set trainingCategory = craft.categories.group('trainingCategoryGroup').slug(querySlug) %} {# And merge them into the relationParam array. #} {% set relationParam = relationParam|merge([{ targetElement: trainingCategory }]) %} {% endfor %} {# Avoid passing an array with `['and']` only #} {% if relationParam|length < 2 %} {% set relationParam = '' %} {% endif %} {% set searchParams = { relatedTo: relationParam, section: 'exercisesDb' } %} {# Find your entries #} {% set entries = craft.entries(searchParams).order('level2, title') %}
{% if entries | length %} {% for entry in entries %}

{{ entry.title }}

{% endfor %} {% else %}

No entries could be found with that category.

{% endif %}