2

I'm trying to order my entries by a numeric custom field named score, some of these values can be 0 but unfortunately, it's not getting ordered at all?

{% set users = craft.users.group('influencer').order('score').limit(24) %}

{% if users|length %}
    {% paginate users as pageInfo, pageEntries %}
    {% for user in pageEntries %}

/* New Code */

  {% set users = craft.users.group('influencer').orderBy('score desc').limit(24) %}

          {% if users|length %}

          {% paginate users as pageInfo, pageEntries %}
          {% for user in pageEntries %}
3

Assuming this is in Craft 3, you should be using .orderBy() instead of .order(). Does the following work as expected?

{% set users = craft.users.group('influencer').orderBy('score desc').limit(24) %}

{% paginate users as pageInfo, pageUsers %}

{% for user in pageUsers %}
    {{ user.username }} : {{ user.score }} <br>
{% endfor %}

Here it is in the docs: https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#orderby

Also turn on devMode to be sure that no errors are being suppressed.

  • I need to limit the array for Pagination to work, I've edited my answer with code but it's still not ordering them correctly. – JMKelley May 22 at 21:59
  • How exactly is it ordering them? I just did a local test and this appears to be working. – Ben Croker May 23 at 6:51
  • Alphabetically for some reason? Could it be empty values? – JMKelley May 23 at 10:47
  • Well do any users actually have values store in their score field? – Ben Croker May 23 at 14:06
  • Heh, yeah. 3 out of 5 entries have a user.score – JMKelley May 23 at 14:11

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.