Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T18:52:55.650Z
Answers.Text: 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
Answers.UserDisplayName: Matt Fletcher
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-25T13:25:48.883Z
Answers.LastActivityDate: 2016-03-25T13:25:48.883Z
Answers.UserDisplayName: Matt P
Body: <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>
  
Tags: <relations><order>
Title: How to order by related entry type field
ThreadText: # 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') %}
  
  <ul>
      {# 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) %}
  
          <ul>
              {# Loop through related products by this author #}
              {% for relatedProduct in products %}
                  <li>{{ relatedProduct.title }}</li>
              {% endfor %}
          </ul>
      {% endfor %}
  </ul>
  
  ```
  
  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  
  
  ---
  
  