Entries related to BOTH categories I've got categories setup like this (Parent &amp; Children):

Type
    Tops
    Dresses
    Pants

Colour
    Black
    Red
    Yellow


When I use this in a category filter and choose Dresses and Black, it works fine in terms that it will return entries that are in Dresses and entries that are in Black.

But how can I edit my code so that it returns entries that are ONLY in Dresses and Black (Black Dresses only!)

Below is what I have so far...

{% set productSegmentCategory = craft.categories.slug(craft.request.lastSegment()).first() %}
{% set productCategoriesArray = ['and'] %}

{% set productValues = {
    keywords: craft.request.getParam('keywords'),
    category: craft.request.getParam('category') ? craft.categories.slug(craft.request.getParam('category')) : null,
    order: craft.request.getParam('order') ? craft.request.getParam('order') : 'title asc',
    limit: craft.request.getParam('limit') ? craft.request.getParam('limit') : entryLimit,
} %}

{% set productParameters = {
    search: productValues.keywords,
    order: productValues.order,
    limit: null,
}%}

{% if productSegmentCategory|length %}
    {% set productCategoriesArray = productCategoriesArray|merge([{ targetElement: productSegmentCategory, field: 'productCategories' }]) %}
{% endif %}

{% if productValues.category|length %}
    {% set productCategoriesArray = productCategoriesArray|merge([{ targetElement: productValues.category, field: 'productCategories' }]) %}
{% endif %}

{% if productCategoriesArray|length &gt; 1 %}
  {% set productParameters = productParameters|merge({ relatedTo: productCategoriesArray }) %}
{% endif %}

{% set productEntries = craft.commerce.products(productParameters) %}

{% if productSegmentCategory|length %}
    {% set entry = productSegmentCategory %}
{% endif %}
You can limit to only products that have multiple related categories like so:



{% set dressesCat = craft.categories...first() %}
{% set blackCat = craft.categories...first() %}

{% set products = craft.commerce.products({
    relatedTo: {
        targetElement: ['and', dressesCat, blackCat],
        field: 'productCategories'
    }
} %}