<p>For your first issue, if you are not paginating then your <code>{% else %}</code> should be:</p>

<pre><code>{% set pageEntries = entries.all() %}
</code></pre>

<p>So that the query gets executed. In full:</p>

<pre><code>{% if pagination is defined and pagination == true %}
        {% paginate entries as pageInfo, pageEntries %}
    {% else %}
        {% set pageEntries = entries.all() %}
    {% endif %}
</code></pre>

<p>Regarding the update to your question, it's the same thing.</p>

<p>Until you add <code>.all()</code> to your <code>featuredEvents</code> query (or any query), it's like the query hasn't run yet. Adding <code>.all()</code> executes the query.</p>

<p>Craft is smart enough to still run it without <code>.all()</code> but it will warn you hence the deprecation warning.</p>

<p>You should <a href="https://docs.craftcms.com/v3/dev/element-queries/" rel="nofollow noreferrer">read more about element queries</a> and <a href="https://docs.craftcms.com/v3/dev/element-queries/#executing-element-queries" rel="nofollow noreferrer">how to execute them</a>.</p>

CC BY-SA 4.0
2020-05-01T10:24:57.877Z
Thank you, I amended the question with a similar issue, could you please check that too.
Sameera Thilakasiri
CC BY-SA 4.0
2020-05-01T10:37:19.380Z
Yes, thank you, just coming back by reading the doc.
Sameera Thilakasiri
CC BY-SA 4.0
2020-05-01T09:24:47.547Z
2020-05-01T10:34:54.137Z
2020-05-01T10:34:54.137Z
Oli
<p>on the template </p>

<p><strong>_events.twig</strong></p>

<pre><code>{% include "./components/_listing" with {
  entries: craft.entries.section('events').orderBy('eventStartDate ASC').limit(3),
  columns: 3,
  heading: 'On this month',
  art: 'art3',
  headings: true
} %}
</code></pre>

<p><strong>_listing.twig</strong></p>

<pre><code>{% if pagination is defined and pagination == true %}
        {% paginate entries as pageInfo, pageEntries %}
    {% else %}
        {% set pageEntries = entries %}
    {% endif %}

    &lt;div class="container"&gt;
        &lt;div class="c-listing-items"&gt;
             {% for entry in pageEntries %}
    ~~~~
</code></pre>

<p>"Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them."</p>

<p>The line number is <code>{% for entry in pageEntries %}</code></p>

<p>I referred <a href="https://craftcms.stackexchange.com/questions/30960/explanation-of-deprecation-warnings">Explanation of Deprecation Warnings</a> and <a href="https://craftcms.stackexchange.com/questions/29366/output-deprecation-error">Output deprecation error</a> </p>

<p>But seems I'm away from those two answers.</p>

<p>Can someone suggest me to find a solution for this?</p>

<p><strong>Update:</strong></p>

<pre><code>{% set featuredEvents = craft.entries.section('events').featuredEntry(1).limit(10).orderBy('offerStartDate') %}
</code></pre>

<p><strong>on the template</strong></p>

<pre><code>{% for featuredEvent in featuredEvents %}
</code></pre>

<p>When we limit to 10, why `{% for featuredEvent in featuredEvents %} line highlight for </p>

<pre><code>Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.
</code></pre>

<entries><pagination><deprecation>
Looping through element queries directly has been deprecated
# Looping through element queries directly has been deprecated

(Asked by: username_0 on 2020-04-30)

on the template 
_events.twig
{% include "./components/_listing" with {
  entries: craft.entries.section('events').orderBy('eventStartDate ASC').limit(3),
  columns: 3,
  heading: 'On this month',
  art: 'art3',
  headings: true
} %}

_listing.twig
{% if pagination is defined and pagination == true %}
        {% paginate entries as pageInfo, pageEntries %}
    {% else %}
        {% set pageEntries = entries %}
    {% endif %}

    
        
             {% for entry in pageEntries %}
    ~~~~

"Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them."
The line number is {% for entry in pageEntries %}
I referred Explanation of Deprecation Warnings and Output deprecation error 
But seems I'm away from those two answers.
Can someone suggest me to find a solution for this?
Update:
{% set featuredEvents = craft.entries.section('events').featuredEntry(1).limit(10).orderBy('offerStartDate') %}

on the template
{% for featuredEvent in featuredEvents %}

When we limit to 10, why `{% for featuredEvent in featuredEvents %} line highlight for 
Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.

**Tags:** entries, pagination, deprecation

---

## 1 answers

### Answer by username_1 on 2020-05-01. Score: 2 | Accepted answer

For your first issue, if you are not paginating then your {% else %} should be:
{% set pageEntries = entries.all() %}

So that the query gets executed. In full:
{% if pagination is defined and pagination == true %}
        {% paginate entries as pageInfo, pageEntries %}
    {% else %}
        {% set pageEntries = entries.all() %}
    {% endif %}

Regarding the update to your question, it's the same thing.
Until you add .all() to your featuredEvents query (or any query), it's like the query hasn't run yet. Adding .all() executes the query.
Craft is smart enough to still run it without .all() but it will warn you hence the deprecation warning.
You should read more about element queries and how to execute them.

> **Comments:**
> **username_0**: Thank you, I amended the question with a similar issue, could you please check that too.  
> **username_0**: Yes, thank you, just coming back by reading the doc.  

---

