Filter by multiple categories I need to filter a sections entries by more than one category but only return entries that belong to all category id's passed in a URL parameter.

Now I can get the correct output if the id's are hard coded but not if contained in the URL parameter.

URL: ajax-swatches?cats=171,172,179

{% set catPars = craft.request.getParam('cats') %}

{% set swatches = craft.entries({
    section: 'swatches',
    relatedTo: ['and',catPars]
}) %}

I presume the 'relatedTo' section is treating the 'catPars' variable as a single entry and ignoring the ',' and next values?

Any help would be really appreciated :)
Craft's relatedTo takes a model, an ID, or an array of either of these. So if you're passing '171,172,179' It's probably coming through as a string and only reading the first ID.

Try making it an array and looping through the values:

{% set catPars = craft.request.getParam('cats')|split(',') %}
{% set related = ['and'] %}
{% for catPar in catPars %}
    {% set related = related|merge([{targetElement: catPar}]) %}
{% endfor %}


{% set swatches = craft.entries({ section: 'swatches', relatedTo: related }) %}


Without knowing your setup I don't know if it's actually targetElement or sourceElement. You can also pass in the field name as well if you want to get more specific. See the documentation linked above for the definitions of all of those.