How do you sort custom section posts by front matter variable? [SOLVED]

Hi guys,

It’s the second day I’m on this and I can’t get it working. There is similar looking post here, but it is not filtering by Section, so it’s of no help to me.

Here’s the starting point: I’m pulling in all the articles from Section “tests” and it works fine:

{{ range where .Data.Pages "Section" "tests" }}
{{ .Render "tests-box" }}
{{ end }} 

I want to sort them by their front-matters’ variable “idnumber” (which are in format “001”, “002” and so on) . I tried hacking the following (and all possible variations), but it does not work:

{{ (range where .Data.Pages "Section" "tests").GroupByParam "idnumber" }}
{{ .Render "tests-box" }}
{{ end }} 

Please advise. Thank you.

I don’t think the SortBy concept is exposed (typing issues?).

Could you move/copy your idnumber value to the frontmatter ‘weight’? Iirc, the default ordering is Weight -> Date. That should solve your problem using your first code block.

1 Like

Logical. Thank you! It could be substituted by weight indeed!