Answers.Body: <p>You can add the "non-empty body" conditional to your parameters, as follows:</p>
  
  <pre><code>{% set params = craft.entries.section('portfolio').body(':notempty:') %}
  {% set previousEntry = entry.getPrev(params) %}
  {% set nextEntry = entry.getNext(params) %}
  {# …and so forth #}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-20T15:12:13.663Z
Answers.LastActivityDate: 2017-04-20T15:12:13.663Z
Answers.UserDisplayName: Stephen Lewis
Body: <p>Not sure if what I am looking is possible, but basically I have a section ('portfolio').  At the bottom of each entry I have links to the previous and next entry. Simple.  </p>
  
  <p>My trouble is that the body field in my entries is not always populated, and because of this I would like to by-pass these ones in my nav at the bottom of an entry page.</p>
  
  <p>See my code below which is not working, I have a feeling that my logic is not going in the right direction at all with this...</p>
  
  <pre><code>{% set params = craft.entries.section('portfolio') %}
  
  {% set prevEntry = entry.getPrev(params) %}
  {% set nextEntry = entry.getNext(params) %}
  
  {% if prevEntry and prevEntry.body | length %}
      {% set image = prevEntry.portfolioImages.first() %}
      &lt;a href="{{ prevEntry.url }}"&gt;Previous&lt;/a&gt;
  {% endif %}
  
  {% if nextEntry and nextEntry.body | length %}
      {% set image = nextEntry.portfolioImages.first() %}
      &lt;a href="{{ nextEntry.url }}"&gt;Next&lt;/a&gt;
  {% endif %}
  </code></pre>
  
Tags: <entries><previous-next>
Title: Next and Previous Entries that match condition?
ThreadText: # Next and Previous Entries that match condition?
  
  (Asked by: username_0 on 2017-04-20)
  
  Not sure if what I am looking is possible, but basically I have a section ('portfolio'). At the bottom of each entry I have links to the previous and next entry. Simple.
  
  My trouble is that the body field in my entries is not always populated, and because of this I would like to by-pass these ones in my nav at the bottom of an entry page.
  
  See my code below which is not working, I have a feeling that my logic is not going in the right direction at all with this...
  
  ```
  {% set params = craft.entries.section('portfolio') %}
  
  {% set prevEntry = entry.getPrev(params) %}
  {% set nextEntry = entry.getNext(params) %}
  
  {% if prevEntry and prevEntry.body | length %}
      {% set image = prevEntry.portfolioImages.first() %}
      <a href="{{ prevEntry.url }}">Previous</a>
  {% endif %}
  
  {% if nextEntry and nextEntry.body | length %}
      {% set image = nextEntry.portfolioImages.first() %}
      <a href="{{ nextEntry.url }}">Next</a>
  {% endif %}
  
  ```
  
  **Tags:** entries, previous-next
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-04-20. Score: 2 | Accepted answer
  
  You can add the "non-empty body" conditional to your parameters, as follows:
  
  ```
  {% set params = craft.entries.section('portfolio').body(':notempty:') %}
  {% set previousEntry = entry.getPrev(params) %}
  {% set nextEntry = entry.getNext(params) %}
  {# …and so forth #}
  
  ```
  
  
  ---
  
  