Answers.Body: <p>The code you currently have (after fixing the <code>arrowsParams</code> typo) will only work on entries that happen to have the very first category in the Seasons category group selected, because this <code>title</code> parameter is actually not getting any value right now:</p>
  
  <pre><code>.title(entry.season.title)
  </code></pre>
  
  <p>Why? Because <code>entry.season</code> is not going to return the first category you have selected in your Season categories field; it’s going to return an <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel</a> that is prepped to return the category(s) selected in your Season categories field, once one of its <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#fetching-the-elements" rel="nofollow">output functions</a> have been called.</p>
  
  <p>Since <code>entry.season</code> is an ElementCriteriaModel, <code>entry.season.title</code> is actually just going to return its current <a href="http://buildwithcraft.com/docs/templating/craft.categories#title" rel="nofollow"><code>title</code></a> parameter value (which is <code>null</code> by default). So this:</p>
  
  <pre><code>{% set category = craft.categories.group('seasons').title(entry.season.title).first() %}
  </code></pre>
  
  <p>is really the same as this:</p>
  
  <pre><code>{% set category = craft.categories.group('seasons').title(null).first() %}
  </code></pre>
  
  <p>which is the same as not including the parameter at all, so it’s also the same as this:</p>
  
  <pre><code>{% set category = craft.categories.group('seasons').first() %}
  </code></pre>
  
  <p>So <code>category</code> is always going to be set to the first category in the group, and <code>arrowsParams</code> is going to be set to all of the Blog entries that are related to that first category.</p>
  
  <p>If the entry you’re viewing <em>doesn’t</em> have that first category selected, then its getNext() and getPrev() functions won’t return anything. (If they can’t determine where the current entry fits into the parameters that were passed in, they can’t determine what the next and previous entries would be.)</p>
  
  <p>Anyway, to fix this, you would need to put a <code>.first()</code> call inside that <code>title</code> param when setting the current category:</p>
  
  <pre><code>{% set category = craft.categories.group('seasons').title(entry.season.first().title).first() %}
  </code></pre>
  
  <p>But here’s the thing: <code>entry.season.first()</code> <strong>is already the category you’re trying to get.</strong> So there’s no point in fetching it through a second <code>craft.categories</code> query in the first place. This will do just fine:</p>
  
  <pre><code>{% set category = entry.season.first() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-23T14:06:38.027Z
Answers.LastActivityDate: 2014-08-23T14:06:38.027Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I currently have one entry in a page and would like to display next and previous arrows. The next/previous entries should be in the same section and related to the same category. To do this I have written this code:</p>
  
  <pre><code>{% set category = craft.categories.group('seasons').title(entry.season.title).first() %}
  {% set arrowsParams = craft.entries.section('blog').relatedTo(category) %}
  {% set nextEntry = entry.getNext(arrowParams) %}
  {% set prevEntry = entry.getPrev(arrowParams) %}
  </code></pre>
  
  <p>For each entry I have added a field 'season' which maps to a category.</p>
  
  <p>When retrieving the nextEntry, the relatedTo category is being neglected and an entry in a different category is being returned. </p>
  
  <p>When I do</p>
  
  <pre><code>craft.entries.section('blog').relatedTo(category).first()
  </code></pre>
  
  <p>it works fine and actually retrieves the first entry in that category.</p>
  
  <p>Am  I missing something? Could this be done?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-23T09:22:46.650Z
Comments.Text: Maybe it's as easy as fixing the typo `arrowsParams`, shanti?
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-23T09:37:49.327Z
Comments.Text: oohh, that was stupid!
Comments.UserDisplayName: Maria Stellini
Tags: <categories>
Title: entries related To category not working with getNext function
ThreadText: # entries related To category not working with getNext function
  
  (Asked by: username_0 on 2014-08-23)
  
  I currently have one entry in a page and would like to display next and previous arrows. The next/previous entries should be in the same section and related to the same category. To do this I have written this code:
  
  ```
  {% set category = craft.categories.group('seasons').title(entry.season.title).first() %}
  {% set arrowsParams = craft.entries.section('blog').relatedTo(category) %}
  {% set nextEntry = entry.getNext(arrowParams) %}
  {% set prevEntry = entry.getPrev(arrowParams) %}
  
  ```
  
  For each entry I have added a field 'season' which maps to a category.
  
  When retrieving the nextEntry, the relatedTo category is being neglected and an entry in a different category is being returned.
  
  When I do
  
  ```
  craft.entries.section('blog').relatedTo(category).first()
  
  ```
  
  it works fine and actually retrieves the first entry in that category.
  
  Am I missing something? Could this be done?
  
  **Tags:** categories
  
  > **Comments:**
  > **username_1**: Maybe it's as easy as fixing the typo `arrowsParams`, shanti?  
  > **username_0**: oohh, that was stupid!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-08-23. Score: 4 | Accepted answer
  
  The code you currently have (after fixing the `arrowsParams` typo) will only work on entries that happen to have the very first category in the Seasons category group selected, because this `title` parameter is actually not getting any value right now:
  
  ```
  .title(entry.season.title)
  
  ```
  
  Why? Because `entry.season` is not going to return the first category you have selected in your Season categories field; it’s going to return an [ElementCriteriaModel](http://buildwithcraft.com/docs/templating/elementcriteriamodel) that is prepped to return the category(s) selected in your Season categories field, once one of its [output functions](http://buildwithcraft.com/docs/templating/elementcriteriamodel#fetching-the-elements) have been called.
  
  Since `entry.season` is an ElementCriteriaModel, `entry.season.title` is actually just going to return its current [`title`](http://buildwithcraft.com/docs/templating/craft.categories#title) parameter value (which is `null` by default). So this:
  
  ```
  {% set category = craft.categories.group('seasons').title(entry.season.title).first() %}
  
  ```
  
  is really the same as this:
  
  ```
  {% set category = craft.categories.group('seasons').title(null).first() %}
  
  ```
  
  which is the same as not including the parameter at all, so it’s also the same as this:
  
  ```
  {% set category = craft.categories.group('seasons').first() %}
  
  ```
  
  So `category` is always going to be set to the first category in the group, and `arrowsParams` is going to be set to all of the Blog entries that are related to that first category.
  
  If the entry you’re viewing *doesn’t* have that first category selected, then its getNext() and getPrev() functions won’t return anything. (If they can’t determine where the current entry fits into the parameters that were passed in, they can’t determine what the next and previous entries would be.)
  
  Anyway, to fix this, you would need to put a `.first()` call inside that `title` param when setting the current category:
  
  ```
  {% set category = craft.categories.group('seasons').title(entry.season.first().title).first() %}
  
  ```
  
  But here’s the thing: `entry.season.first()` **is already the category you’re trying to get.** So there’s no point in fetching it through a second `craft.categories` query in the first place. This will do just fine:
  
  ```
  {% set category = entry.season.first() %}
  
  ```
  
  
  ---
  
  