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

CC BY-SA 4.0
2018-06-22T19:08:57.153Z
2018-06-22T19:08:57.153Z
Robin Schambach
<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>

<templating><error-message>
How do I clear deprecation errors for looping through element queries?
# 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 %} 

{% endfor %}

{{ first.title }}

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


---

