Iterate in multiple sections

Hello,

I want to iterate through two sections “post” and “article”.
Selecting content from only one section works:
{{ range first 3 (where .Pages “Section” “post”).ByLastmod }}

but when I try something like “post” or “article”, it fails.
{{ range first 3 (where .Pages “Section” (“post”||“article”)).ByLastmod }}

What is the correct syntax?

Hi,

you could try using union before:

{{ $pages := union (where .Pages "Section" "post") (where .Pages "Section" "article") }}
{{ range first 3 $pages.ByLastmod }}

I just checked that with my blog/test site and it worked just fine, combining pages from 2 different sections as you seem to intend.

union is documented here: https://gohugo.io/functions/union/

I think you want to use “in”
{{ range first 3 (where .Pages “Section” “in” [“post”,“article”]).ByLastmod }}

Thanks, it works for me!