Filtering collection on internal tag not working

I’m trying to prevent posts with an internal tag (#archive) from appearing in my collection, but I still want them to be accessible (I don’t want to unpublish).

I’ve created the following route:

collections:
  /events/:
    permalink: /{slug}/
    template: events
    filter: primary_tag:event+tag:-hash-archive
    order: featured desc, updated_at desc, created_at desc

Posts with the #archive tag are still appearing.

What am I doing wrong?

Your syntax looks right, but perhaps the answer hinges on exactly what the “+” combination operator means. Does it mean:

  1. Combine all the posts with a primary tag of event with all the posts not tagged “#archive
    OR
  2. Only display all the posts where the primary_tag is “event” AND the posts are not tagged “#archive”.

If you seeing some posts in this filter that have '#archive" but don’t have the primary tag of “event”, then I guess the logic being used is the first one.

If you’re self-hosting Ghost, try restarting your server with the command ghost restart
It happens to us frequently when changing routes, I guess there is some sort of caching problem.

Another thing that works sometimes, removing all tags from the post, saving, adding the tags again and saving.

Otherwise, check that your tags are set correctly in your posts.

1 Like

The syntax was correct. However, it appears the problem was how I was generating the posts collection in index.hbs:

{{#get "posts" limit="100" filter="tags:event" include="tags,authors" order="featured desc, updated_at desc, created_at desc" as |related|}}

The filter in the #get seems to have overridden the filter in the route.

Updating the #get filter fixed this:

{{#get "posts" limit="100" filter="tags:event+tags:-hash-archive" include="tags,authors" order="featured desc, updated_at desc, created_at desc" as |related|}}

Note: I didn’t have to change the route for this to work.

3 Likes

Right. Get ignores routing…

1 Like