1

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

    <div class="container">
        <div class="c-listing-items">
             {% 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.
2

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.

| improve this answer | |
  • Thank you, I amended the question with a similar issue, could you please check that too. – Sameera Thilakasiri May 1 at 10:24
  • Yes, thank you, just coming back by reading the doc. – Sameera Thilakasiri May 1 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.