Answers.Body: <p>What about using the <code>all()</code> function as well? Your field doesn't contain an array, it contains the same type of object like <code>craft.entries</code> provides.</p>
  
  <pre><code>{% for flag in country.all() %}
  </code></pre>
  
  <p>It doesn't appear because you have a loop in a loop it appears because you treat and object as an array</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-22T19:08:57.153Z
Answers.LastActivityDate: 2018-06-22T19:08:57.153Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I am getting this depreciation messages.  </p>
  
  <blockquote>
    <p>Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.</p>
  </blockquote>
  
  <p>In the example below, <strong>the depreciation message refers to the 2nd <code>loop</code> <code>for flag in country</code></strong>.  The message appears anytime I have a loop within a loop.     </p>
  
  <p><strong>How do I template this to avoid the deprecation message?</strong></p>
  
  <pre><code>{% set entries = craft.entries.section('posts').all() %}
  
  {% for first in entries[0:1] %}
  
  {% set country = first.countryName %}
  
  {% for flag in country %} 
  &lt;span class="flag-icon flag-icon-{{ flag.countryCode }}"&gt;&lt;/span&gt;
  {% endfor %}
  
  &lt;span&gt;{{ first.title }}&lt;/span&gt;
  
   {% endfor %}
  </code></pre>
  
Tags: <templating><error-message>
Title: How do I clear deprecation errors for looping through element queries?
ThreadText: # How do I clear deprecation errors for looping through element queries?
  
  (Asked by: username_0 on 2018-06-22)
  
  I am getting this depreciation messages.
  
  > Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.
  
  In the example below, **the depreciation message refers to the 2nd `loop` `for flag in country`**. The message appears anytime I have a loop within a loop.
  
  **How do I template this to avoid the deprecation message?**
  
  ```
  {% set entries = craft.entries.section('posts').all() %}
  
  {% for first in entries[0:1] %}
  
  {% set country = first.countryName %}
  
  {% for flag in country %} 
  <span class="flag-icon flag-icon-{{ flag.countryCode }}"></span>
  {% endfor %}
  
  <span>{{ first.title }}</span>
  
   {% endfor %}
  
  ```
  
  **Tags:** templating, error-message
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-22. Score: 6 | Accepted answer
  
  What about using the `all()` function as well? Your field doesn't contain an array, it contains the same type of object like `craft.entries` provides.
  
  ```
  {% for flag in country.all() %}
  
  ```
  
  It doesn't appear because you have a loop in a loop it appears because you treat and object as an array
  
  
  ---
  
  