<p>Try something slightly different in concept... </p>

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

<p>Hopefully this will help you make sense of it...</p>

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

&lt;ul&gt;
    {# loop through all author entries #}
    {% for author in authors %}
        &lt;li&gt;{{ author.title }}&lt;/li&gt;

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

        &lt;ul&gt;
            {# Loop through related products by this author #}
            {% for relatedProduct in products %}
                &lt;li&gt;{{ relatedProduct.title }}&lt;/li&gt;
            {% endfor %}
        &lt;/ul&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<p>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.</p>

<p>Craft's relatedTo parameter is the key concept to understand. More info here: <a href="https://craftcms.com/docs/relations" rel="nofollow">https://craftcms.com/docs/relations</a></p>

CC BY-SA 4.0
2019-07-31T18:52:55.650Z
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
Matt Fletcher
CC BY-SA 3.0
2016-03-25T13:25:48.883Z
2016-03-25T13:25:48.883Z
Matt P
<p>Two sections:</p>

<p>1) Products</p>

<p>2) Authors</p>

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

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

<p>Craft does not accept the author field handle in the</p>

<pre><code>.order('authors','title').
</code></pre>

<p>Here is the "Products" template code:</p>

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

<p>What is missing?</p>

<relations><order>
How to order by related entry type field
# How to order by related entry type field

(Asked by: username_0 on 2016-03-23)

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
.order('authors','title').

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?

**Tags:** relations, order


---

## 1 answers

### Answer by username_1 on 2016-03-25. Score: 3

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 %}
        {{ author.title }}

        {# 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 %}
                {{ relatedProduct.title }}
            {% 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

> **Comments:**
> **username_2**: 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  

---

