Filtering range of .Site.Recent by post parameters with where

I’m trying to use range and where to get a list of the x most recent posts which have a specific value for a parameter.

I’m trying this:

{{ range first 10 (where .Site.Recent ".Params.type" "article") }}

That seems to be empty (the ‘type’ parameter is definitely present in the front matter of all posts). I’ve tried simply ‘.type’ but that triggers errors.

I’m using section for another purpose, hence not being able to use it here.

How should I go about getting a list of recent posts with a specific parameter value in their front matter?

I resolved this myself. I didn’t realise that type is a special post parameter which can be accessed through .Type. So the code for this to work was simply:

{{ range first 10 (where .Site.Recent ".Type" "article") }}

Go Hugo!

2 Likes