Organize filtered entries by a specific category I have an array of products that has already been filtered by a brand category. I want to display them in a list ordered by a size category. This is working, but I think there must be a better way:

{% set productList = craft.entries(params) %} 
  {# where params includes a relatedTo parameter already #}

    {% for size in sizes %}
        {% for product in productList %}
            {% if product.sizeCategory.first.id == size.id %}
                {{ product.title }}&lt;br /&gt;
            {% endif %}
        {% endfor %}
    {% endfor %}
You should be able to order them using a combination of the order method (if needed) and group twig filter.

{% set productList = craft.entries.(params).order('title')|group('myCategoriesField.first().title') %}


The problem here is that the products might end up being displayed in the order that the size categories were created (i.e. postDate) and not the category 'size' title. If this is a problem then your solution may in fact be the only way. Have a look at this question for alternative answer and discussion of some of the issues.