Get count of post according to value in frontmatter


I would like to know if it’s possible to get the count of post according to their value in frontmatter.
Here is the context.
I made a recipe site for my family (amazing how much time you have in confinement :smile: ) .
I have a page that lists recipes.
Each recipe has a radio button field to set whether it’s a starter, soup, salad, main dish or dessert.
I’m using this value with a js script to filter them on the front end. Everything works fine.
I’m simply trying to “echo” how many recipes for each value of recipe_type.

I know how to get the count of posts but not the count according to a variable.

I hope I was clear enough to describe my question.

Thank yu in advance.

If count is a variable in the frontmatter of your page like:
count: 3
then using that variable in your page requires the use of Twig on that page. To enable Twig processing of the page Markdown you need to add these lines to the page frontmatter:

    twig: true
twig_first: true

I’m not entirely sure whether or not the twig_first: true is required. Try with and without it.

Then in your page content (Markdown) you can simply use {{ count }}.

Thank you @bleutzinn for your help.
In my case, I’ve actually realized that I should have used taxonomy to make more sense.
It’s then easy to get a count.

Thanks again, it’s appreciated.