Sorting with where and sort

The following statement is returning zero results for me, and I’m not sure why. No errors, just a blank return. What I’m trying to do is first get all entires where total is larger than 92, then sort those entries by “factor” in descending order.

{{ range first 10 (sort (where $.Site.Data.list "total" "gt" "92") "factor" "desc") }}

list.json has 736 entries like this (… meaning there’s more like that):

{
  "itemone": {
    "title": "Item 1",
    "total": 95,
    "factor": 92
  },
  ...
}

Are you getting any results at all with just this? I would guess it’s because "92"is a string.

@bradbice Have a look at https://github.com/kaushalmodi/hugo-debugprint and install it as “theme component” (that’s like a theme, but left of the original theme, see the README), then use the following to see if you get any results in that where request:

{{ $items := where $.Site.Data.list "total" "gt" "92" }}
{{ partial "debugprint" $items }}

If you get a result there, then go up one level (the sort query) and see what’s happening there. These complicated nested queries tend to result in problems. I would change that one line into three. That’s easily debuggable and won’t influence your build speed (in my opinion).

Good catch, though when I change it to

(where $.Site.Data.list "total" "gt" 92)

there is no difference in results (though I know I should maintain this syntax).

Hmm, thanks for the reply! After installing the extra component, it is not returning anything for $items. Does where not work for data content? It should return an array, right?

I would expect it to return an array (Hugo calls it splice). Put your repo or a downsized version of it online so we can test it out.