[Solved] Filtering in collections gives 404 in search results

Hello. I am using filter in my routes.yaml file like so

collections:
  /blog/:
    permalink: /blog/{slug}/
    template: blog
    filter: 'tag:-hash-gallery'

I don’t want any posts with #gallery tag to show on my blog page. However, these #gallery posts are still available in Search results and when a user clicks that search result there is 404 Error. How do I filter my collection without populating my search box full of errors?

SOLUTION: Provide a second collection for the search results to bind to

collections:
  /blog/:
    permalink: /blog/{slug}/
    template: blog
    filter: 'tag:-hash-gallery'
  /gallery/:
    permalink: /gallery/{slug}/
    template: blog
    filter: 'tag:hash-gallery'
1 Like

Should your /gallery/ route filter to just the gallery hash tag, or do you want all content to show up there?

2 Likes

That’s a good point. I think I should add the filter you suggest.

2 Likes