Hugo paginate with where filter does not work

I am at my wit’s end trying to get the pagination filter in Hugo to only show blog posts. I was running v0.80.x on my Ubuntu and I just upgraded to v0.95.0.

But no luck.

The funny thing is,

{{ $pg := (where .Data.Pages "Section" "blog") }}
   {{ range (.Paginate $pg).Pages }}
                <h2>{{ .Title }}</h2>

shows all pages but this works as expected showing only blog posts.

{{ range (where .Data.Pages "Section" "blog") }}
                <h2>{{ .Title }}</h2>

What am I doing wrong?


You are invoking pagination more than once on the same page.

If you call .Paginator or .Paginate multiple times on the same page, you should ensure all the calls are identical. Once either .Paginator or .Paginate is called while generating a page, its result is cached, and any subsequent similar call will reuse the cached result. This means that any such calls which do not match the first one will not behave as written.

1 Like

I am not invoking more than once. Can @bep clarify?

This certainly is a bug in Hugo. I shall provide further details if needed.




Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Ok will share code soon thanks

I did some testing and it appears my repository is messed up , so I need to get to the bottom of it, some code change broked pagination.

Thanks @jmooring

Hi @girish1729

Did you get to the bottom of this in the end, as i’m having a very similar issue with this on a taxonomy.html template.

Weirdly it works perfectly fine referencing all pages on the list template. But referencing data.pages in a taxonomy template using “where” to filter continually returns all pages for that taxonomy.


I am not sure if my answer is helpful but I had made an error in my single.html _baseof/ file which pointed to the original guess by @jmooring , I was indeed using pagination without my knowledge.

Perhaps you could look for similar mishap? As that is the only possibility here, I did spend a lot of time trying out various things and it did drive me nuts.

@AndyHill If you need additional assistance, please create a new topic and include a link to your project repository or to a minimal reproducible example.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.