<p>If I'm following you correct, you can use a <a href="http://twig.sensiolabs.org/doc/2.x/tags/for.html#adding-a-condition" rel="nofollow noreferrer">conditional in a for loop</a> to do what you want.</p>

<p>So in your case, it would be something like:</p>

<pre><code>{% for entry in craft.entries.section('news').order('articleOrder desc').limit(5).find() if entry.currentYear2 == currentEdition.currentYear2 and currentEdition.currentMonth2 in entry.currentMonth2 %}
   ...
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-03-23T13:16:21.493Z
It's not doing anything different. I have 10 entries total. 6 meet the if statement criteria. When the limit is set at 20, 6 entries are returned. When the limit is set at 5, only 1 entry is returned when I want it to return 5.
afc
CC BY-SA 3.0
2018-03-29T14:18:44.140Z
I think the answer you are looking for is in Brads answer here -> https://craftcms.stackexchange.com/questions/21046/for-loop-if-statement-then-limit?rq=1 That takes into account the amount of times a valid entry has been found....
Gįëł Tėttëłæår
CC BY-SA 3.0
2017-03-19T16:19:05.107Z
2017-03-19T16:19:05.107Z
Brad Bell
<p>I've got a for loop working perfect with a limit of 5. Then I throw in the if statement to filter those entries that correspond with a global variable I have set. The problem is the if statement is after the for loop with the limit and only doing it's thing to the 5 entries and not all of the entries.\</p>

<p>I want to use the if statement on all the entries to return the ones I want, then limit it to 5. In another DIV I have and offset(5), so the rest go there. I hope that makes sense.</p>

<pre><code>{% for entry in craft.entries.section('news').order('articleOrder desc').limit(5).find() %}

    {% if entry.currentYear2 == currentEdition.currentYear2 and currentEdition.currentMonth2 in entry.currentMonth2 %}

        &lt;h2&gt;{{ entry.title }}&lt;/h2&gt;

        &lt;p&gt;{{ entry.body }}&lt;/p&gt;

    {% endif %}

{% endfor %}
</code></pre>

<conditional><forloop><limit>
Limit the for loop returns with an if statement
# Limit the for loop returns with an if statement

(Asked by: username_0 on 2017-03-19)

I've got a for loop working perfect with a limit of 5. Then I throw in the if statement to filter those entries that correspond with a global variable I have set. The problem is the if statement is after the for loop with the limit and only doing it's thing to the 5 entries and not all of the entries.\
I want to use the if statement on all the entries to return the ones I want, then limit it to 5. In another DIV I have and offset(5), so the rest go there. I hope that makes sense.
{% for entry in craft.entries.section('news').order('articleOrder desc').limit(5).find() %}

    {% if entry.currentYear2 == currentEdition.currentYear2 and currentEdition.currentMonth2 in entry.currentMonth2 %}

        {{ entry.title }}

        {{ entry.body }}

    {% endif %}

{% endfor %}

**Tags:** conditional, forloop, limit


---

## 1 answers

### Answer by username_1 on 2017-03-19. Score: 1

If I'm following you correct, you can use a conditional in a for loop to do what you want.
So in your case, it would be something like:
{% for entry in craft.entries.section('news').order('articleOrder desc').limit(5).find() if entry.currentYear2 == currentEdition.currentYear2 and currentEdition.currentMonth2 in entry.currentMonth2 %}
   ...
{% endfor %}

> **Comments:**
> **username_0**: It's not doing anything different. I have 10 entries total. 6 meet the if statement criteria. When the limit is set at 20, 6 entries are returned. When the limit is set at 5, only 1 entry is returned when I want it to return 5.  
> **username_2**: I think the answer you are looking for is in Brads answer here -> https://craftcms.stackexchange.com/questions/21046/for-loop-if-statement-then-limit?rq=1 That takes into account the amount of times a valid entry has been found....  

---

