Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-23T13:16:21.493Z
Answers.Text: 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.
Answers.UserDisplayName: afc
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-29T14:18:44.140Z
Answers.Text: 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....
Answers.UserDisplayName: Gįëł Tėttëłæår
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-19T16:19:05.107Z
Answers.LastActivityDate: 2017-03-19T16:19:05.107Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <conditional><forloop><limit>
Title: Limit the for loop returns with an if statement
ThreadText: # 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 %}
  
          <h2>{{ entry.title }}</h2>
  
          <p>{{ entry.body }}</p>
  
      {% 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](http://twig.sensiolabs.org/doc/2.x/tags/for.html#adding-a-condition) 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....  
  
  ---
  
  