Answers.Body: <p>Your code isn't working because you set the related game(s) to a variable <code>entries</code> (i.e. <code>{% set entries = craft.entries...%}</code>), but you're not actually <em>doing</em> anything with that variable. Then you try to render the link to the related game(s), but you're simply re-using the <code>entry</code> variable – which refers to the review entry, not the related game entry.</p>
  
  <p>If you change </p>
  
  <pre><code>{% set entries = craft.entries.section('games').relatedTo(entry) %}
  &lt;h3&gt;Game link:&lt;/h3&gt;
  ...
  </code></pre>
  
  <p>to something like</p>
  
  <pre><code>{% set relatedGames = craft.entries.section('games').relatedTo(entry) %}
  {% if relatedGames|length %}
      &lt;h3&gt;Game Link:&lt;/h3&gt;
      &lt;ul&gt;
          {% for game in relatedGames %}
              &lt;li&gt;&lt;a href="{{ game.url }}" title="{{ game.title }}"&gt;{{ game.title }}&lt;/a&gt;&lt;/li&gt;
          {% endfor %}
      &lt;/ul&gt;
  {% endif %}
  </code></pre>
  
  <p>...it should work.</p>
  
  <p>Note that in some cases, its a good idea to be as specific as possible when you're dealing with <a href="https://craftcms.com/docs/relations" rel="nofollow noreferrer">relations</a>. Simply doing <code>relatedTo(entry)</code> will work, but you can also let Craft know where the relation was created (i.e. in which field), and whether the related elements you're looking for is the <em>source</em> or the <em>target</em> elements for the relation. In this case, then Entries field is on the game entry, which means that the review entry is the <em>target</em> element (i.e. the entry that has been selected in an Entries field), and the game entry is the <em>source</em> element (i.e. the entry that actually has the Entries field in its field layout).</p>
  
  <p>Assuming your Entries field on the game entry has a handle <code>relatedReviews</code>, a more specific <code>relatedTo</code> query for your use case could look like this:</p>
  
  <pre><code>{% set relatedGames = craft.entries.section('games').relatedTo({
      field: 'relatedReviews',
      targetElement: entry
  }) %}
  ...
  </code></pre>
  
  <p>Being specific about relations can be more performant, and helps avoid issues where you might have multiple relations involving the same elements (e.g. if your review and game entries where also related via a different Entries field).</p>
  
  <p>Another detail to note is that whenever you're dealing with the <em>source</em> element (e.g. if this was the template for the game entry, and you wanted to list the related review entries), you rarely need <code>relatedTo</code> – you can just do this (of course, replace <code>relatedReviews</code> with the real handle for your Entries field):</p>
  
  <pre><code>{% set relatedReviews = entry.relatedReviews %}
  {% for review in relatedReviews %}
      &lt;a href="{{ review.url }}"&gt;{{ review.title }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-29T00:55:40.807Z
Answers.Text: Your code worked perfect, thanks! I do have related reviews listed on the game entry templates. I am doing it in the following way but would love to know if my code is less-efficient than yours: {% set reviews = entry.GamesReviews  %}{% if reviews|length %}<h3>Reviews:</h3><ul>{% for review in reviews.order('title asc') %} <li><a href="{{ review.url }}" title="{{ review.title }}">{% for category in review.ReviewsMedia %}{{ category.title }}{% endfor %} - {{ review.title }}</a></li>{% endfor %}</ul>{% endif %}
Answers.UserDisplayName: DevServe
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-28T08:50:32.097Z
Answers.LastActivityDate: 2016-12-28T08:50:32.097Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I have a section called reviews and a section called games.
  A entry field in games is creating a relationship to reviews.</p>
  
  <p>On my _entry.html entry for reviews, I want to link back to the related game.</p>
  
  <p>My code is below. I understand why it isn't working, but not sure how to fix it.</p>
  
  <p>The template displays the Review entry title, the body some extra fields in reviews.</p>
  
  <p>And then gets to the Game Link, but the link is not to my Games section but to my Reviews section.</p>
  
  <p>In other words, on this review:
  <a href="http://www.colorcomputergames.com/reviews/1984-01-01/glaxxons" rel="nofollow noreferrer">http://www.colorcomputergames.com/reviews/1984-01-01/glaxxons</a></p>
  
  <p>The link at the bottom should be to:
  <a href="http://www.colorcomputergames.com/games/glaxxons" rel="nofollow noreferrer">http://www.colorcomputergames.com/games/glaxxons</a></p>
  
  <p>But instead, goes to:
  <a href="http://www.colorcomputergames.com/reviews/1984-01-01/glaxxons" rel="nofollow noreferrer">http://www.colorcomputergames.com/reviews/1984-01-01/glaxxons</a></p>
  
  <pre><code>&lt;h1&gt;{{ entry.title }}&lt;/h1&gt;
  &lt;ul&gt;
      {% if entry.ReviewsAuthor|length %}&lt;li&gt;Reviewer: {{ entry.ReviewsAuthor }}&lt;/li&gt;{% endif %}
      {% if entry.ReviewsMedia|length %}&lt;li&gt;Media: {% for category in entry.ReviewsMedia %}&lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;{% endfor %}&lt;/li&gt;{% endif %}
      {% if entry.ReviewsDate|length %}&lt;li&gt;Date: {{ entry.ReviewsDate.format('F Y') }}&lt;/li&gt;{% endif %}
      {% if entry.ReviewsRelatedLink|length %}&lt;li&gt;Related Link: {{ entry.ReviewsRelatedLink }}&lt;/li&gt;{% endif %}
  &lt;/ul&gt;
  {{ entry.body }}
  
  {% set entries = craft.entries.section('games').relatedTo(entry) %}
  &lt;h3&gt;Game Link:&lt;/h3&gt;
      &lt;ul&gt;                      
          &lt;li&gt;&lt;a href="{{ entry.url }}" title="{{ entry.title }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  </code></pre>
  
  <p>As mentioned, in section called Games, I have a field called GamesReview and set it to entries and assign the review entry. Do I need to do the opposite as well t make this work? That is, in my reviews section, create a field called GameReviewed and set it to entries and assign it to Games section.</p>
  
  <p>Thanks</p>
  
Tags: <relations><sections>
Title: Link to an entry to a related section
ThreadText: # Link to an entry to a related section
  
  (Asked by: username_0 on 2016-12-28)
  
  I have a section called reviews and a section called games.
  A entry field in games is creating a relationship to reviews.
  
  On my \_entry.html entry for reviews, I want to link back to the related game.
  
  My code is below. I understand why it isn't working, but not sure how to fix it.
  
  The template displays the Review entry title, the body some extra fields in reviews.
  
  And then gets to the Game Link, but the link is not to my Games section but to my Reviews section.
  
  In other words, on this review:
  <http://www.colorcomputergames.com/reviews/1984-01-01/glaxxons>
  
  The link at the bottom should be to:
  <http://www.colorcomputergames.com/games/glaxxons>
  
  But instead, goes to:
  <http://www.colorcomputergames.com/reviews/1984-01-01/glaxxons>
  
  ```
  <h1>{{ entry.title }}</h1>
  <ul>
      {% if entry.ReviewsAuthor|length %}<li>Reviewer: {{ entry.ReviewsAuthor }}</li>{% endif %}
      {% if entry.ReviewsMedia|length %}<li>Media: {% for category in entry.ReviewsMedia %}<a href="{{ category.url }}">{{ category.title }}</a>{% endfor %}</li>{% endif %}
      {% if entry.ReviewsDate|length %}<li>Date: {{ entry.ReviewsDate.format('F Y') }}</li>{% endif %}
      {% if entry.ReviewsRelatedLink|length %}<li>Related Link: {{ entry.ReviewsRelatedLink }}</li>{% endif %}
  </ul>
  {{ entry.body }}
  
  {% set entries = craft.entries.section('games').relatedTo(entry) %}
  <h3>Game Link:</h3>
      <ul>                      
          <li><a href="{{ entry.url }}" title="{{ entry.title }}">{{ entry.title }}</a></li>
      </ul>
  
  ```
  
  As mentioned, in section called Games, I have a field called GamesReview and set it to entries and assign the review entry. Do I need to do the opposite as well t make this work? That is, in my reviews section, create a field called GameReviewed and set it to entries and assign it to Games section.
  
  Thanks
  
  **Tags:** relations, sections
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-12-28. Score: 1 | Accepted answer
  
  Your code isn't working because you set the related game(s) to a variable `entries` (i.e. `{% set entries = craft.entries...%}`), but you're not actually *doing* anything with that variable. Then you try to render the link to the related game(s), but you're simply re-using the `entry` variable – which refers to the review entry, not the related game entry.
  
  If you change
  
  ```
  {% set entries = craft.entries.section('games').relatedTo(entry) %}
  <h3>Game link:</h3>
  ...
  
  ```
  
  to something like
  
  ```
  {% set relatedGames = craft.entries.section('games').relatedTo(entry) %}
  {% if relatedGames|length %}
      <h3>Game Link:</h3>
      <ul>
          {% for game in relatedGames %}
              <li><a href="{{ game.url }}" title="{{ game.title }}">{{ game.title }}</a></li>
          {% endfor %}
      </ul>
  {% endif %}
  
  ```
  
  ...it should work.
  
  Note that in some cases, its a good idea to be as specific as possible when you're dealing with [relations](https://craftcms.com/docs/relations). Simply doing `relatedTo(entry)` will work, but you can also let Craft know where the relation was created (i.e. in which field), and whether the related elements you're looking for is the *source* or the *target* elements for the relation. In this case, then Entries field is on the game entry, which means that the review entry is the *target* element (i.e. the entry that has been selected in an Entries field), and the game entry is the *source* element (i.e. the entry that actually has the Entries field in its field layout).
  
  Assuming your Entries field on the game entry has a handle `relatedReviews`, a more specific `relatedTo` query for your use case could look like this:
  
  ```
  {% set relatedGames = craft.entries.section('games').relatedTo({
      field: 'relatedReviews',
      targetElement: entry
  }) %}
  ...
  
  ```
  
  Being specific about relations can be more performant, and helps avoid issues where you might have multiple relations involving the same elements (e.g. if your review and game entries where also related via a different Entries field).
  
  Another detail to note is that whenever you're dealing with the *source* element (e.g. if this was the template for the game entry, and you wanted to list the related review entries), you rarely need `relatedTo` – you can just do this (of course, replace `relatedReviews` with the real handle for your Entries field):
  
  ```
  {% set relatedReviews = entry.relatedReviews %}
  {% for review in relatedReviews %}
      <a href="{{ review.url }}">{{ review.title }}</a>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Your code worked perfect, thanks! I do have related reviews listed on the game entry templates. I am doing it in the following way but would love to know if my code is less-efficient than yours: {% set reviews = entry.GamesReviews  %}{% if reviews|length %}<h3>Reviews:</h3><ul>{% for review in reviews.order('title asc') %} <li><a href="{{ review.url }}" title="{{ review.title }}">{% for category in review.ReviewsMedia %}{{ category.title }}{% endfor %} - {{ review.title }}</a></li>{% endfor %}</ul>{% endif %}  
  
  ---
  
  