<p>I want to create a basic product listing page based on categories. I created a template that dynamically shows all items based on the category that is passed to it <a href="https://craftcms.stackexchange.com/questions/37007/paginate-based-on-items-in-a-category">based on the help I received here</a>. That solution works great, but I'm getting the <a href="https://craftcms.stackexchange.com/questions/35244/looping-through-element-queries-directly-has-been-deprecated">Deprecation warning</a> others have received: <em>Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.</em></p>
<p>Here is my solution that works, but throws the deprecation:</p>
<pre><code>{% set query = craft.entries()
    .section('mySection')
    .relatedTo(category)
    .limit(10)
%}

{% paginate query as pageInfo, pageEntries %}

{% for entry in pageEntries %}
     &lt;p&gt;&lt;a href=&quot;{{ entry.url }}&quot;&gt;{{entry.title}}&lt;/a&gt;&lt;/p&gt;
{% endfor %}

{% if pageInfo.prevUrl %}&lt;a href=&quot;{{ pageInfo.prevUrl }}&quot;&gt;Previous Page&lt;/a&gt;{% endif %}
{% if pageInfo.nextUrl %}&lt;a href=&quot;{{ pageInfo.nextUrl }}&quot;&gt;Next Page&lt;/a&gt;{% endif %}
</code></pre>
<p>I've looked through all the questions and answers here, and gone back to the documentation on pagination, <a href="https://craftcms.com/docs/3.x/dev/tags.html#paginate" rel="nofollow noreferrer">which still uses limit()</a>, <strong>but I can't figure out how I can paginate if I'm not able to use limit() and instead have to use all()?</strong></p>
<p>I'm new to Craft so it's entirely possible I'm missing something simple.</p>

CC BY-SA 4.0
2021-01-22T07:04:03.780Z
This should work. Are you sure the warning isn't left over from a previous attempt? If you clear it in the control panel then refresh your page, does it come back? Any other query on the page?
Oli
CC BY-SA 4.0
2021-01-22T22:50:19.600Z
I cleared it (which I didn't realize I could do) and it does seem fine. I was thrown by the various posts (and error) that said all() was needed. Thanks.
doctorgloom
CC BY-SA 4.0
2021-07-12T15:40:35.703Z
I'm still facing the same issue with this pagination syntax. Even after clearing the deprecation error, it surfaces again after awhile. Any tips?
HG Tan
CC BY-SA 4.0
2021-07-12T21:29:02.057Z
@HGTan sorry, but unfortunately I don't have any tips. For me it was fine after clearing errors, and I'm still relatively new with Craft. Maybe check if you have any other queries on the page that could be causing it.
doctorgloom
<categories><error-message><pagination><deprecation>
How do you Paginate if Looping through element queries directly is deprecated?
# How do you Paginate if Looping through element queries directly is deprecated?

(Asked by: username_0 on 2021-01-21)

I want to create a basic product listing page based on categories. I created a template that dynamically shows all items based on the category that is passed to it based on the help I received here. That solution works great, but I'm getting the Deprecation warning others have received: Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.
Here is my solution that works, but throws the deprecation:
{% set query = craft.entries()
    .section('mySection')
    .relatedTo(category)
    .limit(10)
%}

{% paginate query as pageInfo, pageEntries %}

{% for entry in pageEntries %}
     {{entry.title}}
{% endfor %}

{% if pageInfo.prevUrl %}Previous Page{% endif %}
{% if pageInfo.nextUrl %}Next Page{% endif %}

I've looked through all the questions and answers here, and gone back to the documentation on pagination, which still uses limit(), but I can't figure out how I can paginate if I'm not able to use limit() and instead have to use all()?
I'm new to Craft so it's entirely possible I'm missing something simple.

**Tags:** categories, error-message, pagination, deprecation

> **Comments:**
> **username_1**: This should work. Are you sure the warning isn't left over from a previous attempt? If you clear it in the control panel then refresh your page, does it come back? Any other query on the page?  
> **username_0**: I cleared it (which I didn't realize I could do) and it does seem fine. I was thrown by the various posts (and error) that said all() was needed. Thanks.  
> **username_2**: I'm still facing the same issue with this pagination syntax. Even after clearing the deprecation error, it surfaces again after awhile. Any tips?  
> **username_0**: @HGTan sorry, but unfortunately I don't have any tips. For me it was fine after clearing errors, and I'm still relatively new with Craft. Maybe check if you have any other queries on the page that could be causing it.  

---

## 0 answers

