<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>

CC BY-SA 3.0
2017-04-20T15:12:13.663Z
2017-04-20T15:12:13.663Z
Stephen Lewis
<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>

<entries><previous-next>
Next and Previous Entries that match condition?
# 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() %}
    Previous
{% endif %}

{% if nextEntry and nextEntry.body | length %}
    {% set image = nextEntry.portfolioImages.first() %}
    Next
{% 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 #}


---

