<p>Looks to me like your solution is mostly correct, except for handling the <code>gamesCatalogNumber</code>. For that you could either:</p>

<ul>
<li>test for specific publisher(s) by id or slug</li>
<li>test if gamesCatalogNumber is empty on the first entry (and assume that the publisher doesn't use catalog numbers), or </li>
<li>(recommended solution) add a <code>checkbox</code> or <code>lightSwitch</code> field to the publisher called 'usesCatalogNumbers' and test for that.</li>
</ul>

<p>Something like:</p>

<pre><code>{# publisher template #}

{% if entry.usesCatalogNumbers %}
    {% set games = craft.entries.section('games').relatedTo(entry).order('gamesCatalogNumber desc') %}
{% else %}
    {% set games = craft.entries.section('games').relatedTo(entry).order('title asc') %}
{% endif %}

&lt;ul&gt;
    {% for game in games %}
        &lt;li&gt;{% if entry.usesCatalogNumbers %}{{ entry.gamesCatalogNumber }}: {% endif %}&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;

{% set params = craft.entries.section('publishers').order('title asc') %}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{% if prevEntry %}&lt;a href="{{ prevEntry.url }}"&gt;Previous Publisher&lt;/a&gt; {% endif %}{% if nextEntry %}&lt;a href="{{ nextEntry.url }}"&gt;Next Publisher&lt;/a&gt;{% endif %}
</code></pre>

<p>I recommend this (instead of the other options) because it's a bit more explicit and extensible (i.e. allows you to add other publishers that use catalog numbers without modifying the templates).</p>

CC BY-SA 3.0
2016-12-29T01:44:44.730Z
Revisiting this... Setting aside the Publisher section aspect of the original post. I think I just want to list out all games that contains 'something' (not null) in the field GamesCatalogNumber. Running into problems also getting it to work with pagination. :-(
DevServe
CC BY-SA 3.0
2016-12-28T00:11:28.687Z
2016-12-28T00:28:01.067Z
2016-12-28T00:28:01.067Z
Douglas McDonald
<p>I have two sections:<br>
Games<br>
Publishers</p>

<p>Games has a field called 'GamesPublisher' that is Entries type (set to Publishers)</p>

<p>I have a publisher called 'Microsoft' with an ID of 49.</p>

<p>I want to display all Game entries for the Publisher 'Microsoft' (ie ID 49)</p>

<p>I also want to set the order of the displaying in ASC order based on the field 'GamesCatalogNumber' which is in the section Games.</p>

<p>So far, it looks OK, but I have yet to figure out to limit entries to a specific Publisher.
<a href="http://www.colorcomputergames.com/tandy-catalog/" rel="nofollow noreferrer">http://www.colorcomputergames.com/tandy-catalog/</a></p>

<pre><code>{% set entries = craft.entries.section('games').relatedTo(entry) %}
    &lt;ul&gt;
    {% for entry in entries.order('GamesCatalogNumber desc') %}
     &lt;li&gt;{{ entry.GamesCatalogNumber }}: &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;

    {# Set parameters for prev/next elements list #}
    {% set params = craft.entries.section('publishers').order('title asc') %}

    {# Get the prev/next elements #}
    {% set prevEntry = entry.getPrev(params) %}
    {% set nextEntry = entry.getNext(params) %}

    {# And make sure to only output the links if the element exists #}
    {% if prevEntry %}&lt;a href="{{ prevEntry.url }}"&gt;Previous Publisher&lt;/a&gt;{% endif %}
    {% if nextEntry %}&lt;a href="{{ nextEntry.url }}"&gt;Next Publisher&lt;/a&gt;{% endif %}
</code></pre>

CC BY-SA 3.0
2016-12-27T03:57:04.720Z
I have the above somewhat working, but I don't think my solution is efficient. As only the publisher 'Microsoft' (ID:49) will every have data in the field GamesCatalogNumber, I put an IF statement to only display the <li> if that field is not empty.
Oddly, it works when the FOR loop is set to order in DESC order but fails in ASC order.
http://www.colorcomputergames.com/tandy-catalog/test.html
DevServe
CC BY-SA 3.0
2016-12-27T12:07:07.857Z
What field type is `GamesCatalogNumber `?
André Elvan
CC BY-SA 3.0
2016-12-29T01:41:45.470Z
@AndréElvan, GamesCatalogNumber is just a TEXT field.
DevServe
CC BY-SA 3.0
2016-12-29T14:25:38.540Z
Regarding the problem with the sorting, if the field is text, it will be sorted as a text string, even if the value is a number, so this will not make any sense. Try changing it to a Number field.
André Elvan
<loop><set><relatedto>
Display all entries matching field of a section
# Display all entries matching field of a section

(Asked by: username_0 on 2016-12-27)

I have two sections:
Games
Publishers
Games has a field called 'GamesPublisher' that is Entries type (set to Publishers)
I have a publisher called 'Microsoft' with an ID of 49.
I want to display all Game entries for the Publisher 'Microsoft' (ie ID 49)
I also want to set the order of the displaying in ASC order based on the field 'GamesCatalogNumber' which is in the section Games.
So far, it looks OK, but I have yet to figure out to limit entries to a specific Publisher.
http://www.colorcomputergames.com/tandy-catalog/
{% set entries = craft.entries.section('games').relatedTo(entry) %}
    
    {% for entry in entries.order('GamesCatalogNumber desc') %}
     {{ entry.GamesCatalogNumber }}: {{ entry.title }}
    {% endfor %}
    

    {# Set parameters for prev/next elements list #}
    {% set params = craft.entries.section('publishers').order('title asc') %}

    {# Get the prev/next elements #}
    {% set prevEntry = entry.getPrev(params) %}
    {% set nextEntry = entry.getNext(params) %}

    {# And make sure to only output the links if the element exists #}
    {% if prevEntry %}Previous Publisher{% endif %}
    {% if nextEntry %}Next Publisher{% endif %}

**Tags:** loop, set, relatedto

> **Comments:**
> **username_0**: I have the above somewhat working, but I don't think my solution is efficient. As only the publisher 'Microsoft' (ID:49) will every have data in the field GamesCatalogNumber, I put an IF statement to only display the <li> if that field is not empty. Oddly, it works when the FOR loop is set to order in DESC order but fails in ASC order. http://www.colorcomputergames.com/tandy-catalog/test.html  
> **username_1**: What field type is `GamesCatalogNumber `?  
> **username_0**: @AndréElvan, GamesCatalogNumber is just a TEXT field.  
> **username_1**: Regarding the problem with the sorting, if the field is text, it will be sorted as a text string, even if the value is a number, so this will not make any sense. Try changing it to a Number field.  

---

## 1 answers

### Answer by username_2 on 2016-12-28. Score: 1

Looks to me like your solution is mostly correct, except for handling the gamesCatalogNumber. For that you could either:

test for specific publisher(s) by id or slug
test if gamesCatalogNumber is empty on the first entry (and assume that the publisher doesn't use catalog numbers), or 
(recommended solution) add a checkbox or lightSwitch field to the publisher called 'usesCatalogNumbers' and test for that.

Something like:
{# publisher template #}

{% if entry.usesCatalogNumbers %}
    {% set games = craft.entries.section('games').relatedTo(entry).order('gamesCatalogNumber desc') %}
{% else %}
    {% set games = craft.entries.section('games').relatedTo(entry).order('title asc') %}
{% endif %}


    {% for game in games %}
        {% if entry.usesCatalogNumbers %}{{ entry.gamesCatalogNumber }}: {% endif %}{{ entry.title }}
    {% endfor %}


{% set params = craft.entries.section('publishers').order('title asc') %}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{% if prevEntry %}Previous Publisher {% endif %}{% if nextEntry %}Next Publisher{% endif %}

I recommend this (instead of the other options) because it's a bit more explicit and extensible (i.e. allows you to add other publishers that use catalog numbers without modifying the templates).

> **Comments:**
> **username_0**: Revisiting this... Setting aside the Publisher section aspect of the original post. I think I just want to list out all games that contains 'something' (not null) in the field GamesCatalogNumber. Running into problems also getting it to work with pagination. :-(  

---

