[Solved] Sort and Where in a range Site.Data

Hello, everybody,

I have a range one Site.Data that works very well.
{{ range first 52 (where .Site.Data.petiteannonce "cityName" "eq" .Params.city) }}

Nevertheless, I would like to sort it by date.

I have a dateadd params that corresponds to a php timestamp.

I started to try this way but it’s still not working.
{{ range first 52 (where .Site.Data.petiteannonce "cityName" "eq" .Params.city (where "dateAdd" "ge" .Now.Unix) ) }}

Thank you in advance for your help.

I am close to the solution with sort but it doesn’t take into account where

{{ range first 52 (sort .Site.Data.petiteannonce "dateAdd" "desc" (where .Site.Data.petiteannonce "cityName" "eq" .Params.city )) }}

Check this out: https://gohugo.io/templates/lists#by-date

Thank you @budparr :stuck_out_tongue:

I think i’ve solved with

{{ range first 12 ((where .Site.Data.petiteannonce "cityName" "eq" .Params.name) sort .Site.Data.petiteannonce "dateAdd" "desc") }}

2 Likes