Closed adrianjean closed 1 year ago
Here's something interesting... Instead of using:
{% do craft.viewCount.sort(entries, 'viewCount') %}
and I use this:
{% do craft.viewCount.sort(entries) %}
I see that all the entries with "0" views are grouped together, and all the entries with 1+ views are together, but not in order.
Ugh... I mixed up "Field Name" for "key" in the {% do craft.viewCount.sort(entries, 'KEY') %}
.
When using the key set in the Field Settings the sort works!!
Ok cool, glad you got it all worked out! 🙂
For some reason the sort function isn't working for me. Here is my setup:
Load entries from two sections, posted in the last 7 days
Sort the Entries
{% do craft.viewCount.sort(entries, 'viewCount') %}
Run Query
{% set entries = entries.all() %}
When I then loop over them with
{% for entry in entries %}
I can see the view counts, but they are not in order. It's as if the sorting doesn't happen.viewCount
is the field that's holding the counter value. It's placed on tab on the entry form.Anything I am doing wrong?
ViewCount: 1.2.2 CraftCMS: 4.5.6.1 PHP: 8.2.11 MYSQL: 8.2.11