0

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 %}
     <p><a href="{{ entry.url }}">{{entry.title}}</a></p>
{% endfor %}

{% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl }}">Previous Page</a>{% endif %}
{% if pageInfo.nextUrl %}<a href="{{ pageInfo.nextUrl }}">Next Page</a>{% 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.

4
  • 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?
    – Oli
    Jan 22 at 7:04
  • 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. Jan 22 at 22:50
  • 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
    Jul 12 at 15:40
  • @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. Jul 12 at 21:29

Your Answer

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

Browse other questions tagged or ask your own question.