1

I'm looking to paginate my tag page, but unfortuntately it throws a fairly strange error. Remove the pagination -> the page works perfectly? Bit confused, the only thing I think it may be is that it's only returning 1 result so errors?

{% set tag = craft.tags.title(tag).first() %}

{% set users = craft.users.group('influencer').relatedTo(tag).order('userTotalFollowers asc').all() %}

{% if users|length %}

{% paginate users as pageInfo, pageUsers %}
{% for user in users %}
  {{ user.username }}
{% endfor %}


<div class="row justify-content-between">
  <div class="col text-left">
    {% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl }}" class="btn btn-outline-secondary">← Previous</a>{% endif %}
  </div>
  <div class="col text-right">
    {% if pageInfo.nextUrl %}<a href="{{ pageInfo.nextUrl }}" class="btn btn-outline-secondary">Next →</a>{% endif %}
  </div>
</div>
{% endif %}

Argument 1 passed to craft\helpers\Template::paginateCriteria() must implement interface yii\db\QueryInterface, array given, called in /app/storage/runtime/compiled_templates/ef/efb8567b56752c2a98d031bc1d51461f73acc6fdd1f2c8872e44feb2af18359c.php on line 133

2

With the all() function at the end of your users-definition you get an array of all users.

The pagination expects a QueryInterface. This is logical: With pagination you do not want to load all users, only the ones listed on the page.

In addition, to paginate, you have to limit() your query to a number of entries.

Therefore: {% set users = craft.users.group('influencer').relatedTo(tag).order('userTotalFollowers asc').limit(10) %} should probably work.

You can find more information and an example in the documentation.

I hope this helps and solves the problem.

|improve this answer|||||
-1

Try modifying the loop to the following: {% for user in pageUsers %}

|improve this answer|||||
-2

All you need to do is add a limit in your user query. This might help you.

|improve this answer|||||

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.