External tags don't display when filtering posts by internal tag

Ghost Version: 2.31.0
Configuration: Local install
Browser: Firefox

I’m trying to display a list of posts with a certain internal tag (ex: #projects) on my home.hbs page. For each post, I want to also display the additional tags on that post (ex: Food, Science, etc.). For some reason, the tags don’t display in the below example:

{{#get "posts" filter="tags:project"}} {{#foreach posts}} <article class="{{post_class}}"> <section class="project-image"> <img src="{{img_url feature_image size="small"}}"/> </section> <section class="project-content"> <h4>{{title}}</h4> {{tags}} <summary>{{excerpt characters="100"}}...</summary> </section> </article> {{/foreach}} {{/get}}

But when I remove the #get helper and just have #foreach, the list of tags is displayed. Can someone help me understand why this is or if it’s a bug?

A couple things:

  • filter="tags:project" should be filter="tag:hash-project" - From what I know, when using tags (plural), you need to pass grouping ([]), but not for tag (not plural). Also, since you’re trying to filter with the internal tag, you need the hash- prefix
  • Removing the get helper will loop over the home page posts which is why tags are displayed
  • If you want to also fetch post tags, you need to use include=tags in the get helper
  • Instead of using the get helper, you can also use Dynamic Routing (just FYI :slight_smile:)

Hope this helps!

Here are the docs I referenced:


1 Like

Thank you very much! The “include=tags” fixed my problem in the above example. I totally missed this in the documentation - thanks for linking the source.

Oddly enough, this ( filter="tags:project" ) actually worked for me to filter out #project tagged posts. I didn’t need the array or the “hash-” in the front.

Out of curiosity, why are the tags and authors attributes treated differently than other post-related attributes? I looked through here (Ghost Handlebars Theme Helpers: get) under “include”, but that wasn’t really clear to me.

I think it’s because of how the database is designed; authors and tags are many-to-many relationships in separate tables, while most of the other data is part of the posts table and one-to-one