Two sections:

1) Products

2) Authors

The "Products" section pulls the author name from the "Authors" section through an entries type field.

I'd like to order the products first by authors (alphabetically), then by title.

Craft does not accept the author field handle in the


Here is the "Products" template code:

{% set entries = craft.commerce.products.type('Products').relatedTo(category) %}
{% for entry in entries.order('author','title').limit(0) %}

What is missing?

1 Answer 1


Try something slightly different in concept...

On your Products template - /products/index.html - start with your Authors first and then look for the Products which are related to them.

Hopefully this will help you make sense of it...

{# find all author entries #}
{% set authors = craft.entries.section('authors').order('title') %}

    {# loop through all author entries #}
    {% for author in authors %}
        <li>{{ author.title }}</li>

        {# find any products which may be related to the author #}
        {% set products = craft.entries.section('products').relatedTo(author) %}

            {# Loop through related products by this author #}
            {% for relatedProduct in products %}
                <li>{{ relatedProduct.title }}</li>
            {% endfor %}
    {% endfor %}

Also, if your Authors will ever need to log in to Craft, then consider adding them as CMS Users instead of entries. I know this has licence fee implications, but it's just a thought.

Craft's relatedTo parameter is the key concept to understand. More info here: https://craftcms.com/docs/relations

  • Great answer, thanks. Sometimes the best thing to do is to shift the paradigm on its head. Ps, some of this syntax is deprecated. You should change order to orderBy and add a .all() to both queries. Will leave it to you as to whether this answer should be for craft 2 or 3 Commented Jul 31, 2019 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.