Filtering by categories AND tags with full match We're trying to filter by categories AND tags in the one form. However can't seem to get things working as we would like. 

Essentially, we have a form that pulls in the tags and allows multiple filtering dropdowns. The below is out results page code, which outputs odd results. We need all params to match the entries categories/tags but it just doesn't work as expected. Where are we going wrong?

    {# Get params #}
    {% set mainCategory = craft.app.request.getParam(‘category’) %}
    {% set season = craft.app.request.getParam(‘season’) %}
    {% set age = craft.app.request.getParam(‘ages’) %}

    {# Set arrays #}
    {% set mainCat = mainCategory ? craft.categories.group(‘courseCategories’).slug(mainCategory).all() %}
    {% set seasonCat = season ? craft.tags.group(‘season’).slug(season).all() %}
    {% set ageCat = age ? craft.tags.group(‘ageRange’).slug(age).all() %}

    {# Set relatedTo #}
    {% set categoryParam = mainCat ? {targetElement: [‘and’]|merge(mainCat)} %}
    {% set seasonParam = seasonCat ? {targetElement: [‘and’]|merge(seasonCat)} %}
    {% set ageParam = ageCat ? {targetElement: [‘and’]|merge(ageCat)} %}

    {# Get entries #}
    {% set relationParams = [categoryParam, seasonParam, ageParam]|filter %}
    {% set entries = craft.entries({
        section: ‘courses’,
        relatedTo: relationParams ? [‘and’]|merge(relationParams) : null
    }) %}
You are always one level too deep. Craft is able to proceed parameters like

[
    'and',
    ['targetElement' =&gt; [1, 2, 3],
    ['targetElement' =&gt; ['or', 1, 2, 3],
    ['targetElement' =&gt; 1],
    ['targetElement' =&gt; ['and', 1, 2, 3]
]


And so on.
Yours is

'targetElement' =&gt; ['and', [1,2,3]]


I would suggest you to dump your array

&lt;pre&gt;
{{ dump(array) }}
&lt;/pre&gt;


To see the result. If you don't care about performance just using .one() instead of all() might solve the problem.