Show related posts from all associated tags

Hi there! I have been messing around with ghost on my local machine for a while now. I would describe myself as a guy that is not a coder/developer, but I do have more knowledge than the average person on websites, hosting, cms’s etc.

So now I am running into an issue that has been going on and on in my head, but I cannot find myself a solution after a long time of googling. So hopefully you guys will be able to help my mind get some rest on this matter :slight_smile:

Imagine a box with 3x3 fields (9 in total). There are some routes to take on this box which are listed on a static page with several post lists (each with their own unique tag of the route).
For example there is route 1 - 4 - 7 but also a route 1 - 4 - 6 - 9.

Using {{#get “posts” filter=“tags:1469” limit=“3” order=“title asc”}} I am able to show all cards that use this tag.
Reference to screenshot on top

So all individual posts explain what to do to go from 1 to 4, 4 to 6 and 6 to 9 etc.

Now for example on the 1 to 4 page I would like related content to be posts: 4 to 7 (part of the 1 - 4 - 7 route), but also 4 to 6 and 6 to 9 (part of the 1 - 4 - 6 - 9 route).

So on the page “1 to 4” I am only getting “4 to 7” as related using this filter: filter=“tags:{{primary_tag.slug}}+id:-{{id}}”
Reference to screenshot on bottom

But I would also like to show post in that same list that have the tag 1469.

Hope my explanation is understandable! If not, I’ll try to formulate it again.

Take care of yourself and your surroundings - cheers, Mike

I don’t fully follow what you’re asking here - the numbers make it confusing.

But I think you’re asking for this:

And specifically this:

{{#get "posts" limit="5" filter="tags:[{{post.tags}}]+id:-{{}}" include="tags" as |related|}}

Which is designed to fetch all posts with at least one tag the same as the current post, and behind the scenes Ghost automagically orders them by the number of matches. So a post with 2 matching tags appears before a post with one matching tag.

1 Like

Hi Hannah! Thanks for your reply :smiley: I believe I tried that option before writing this topic, but when using the code it returns nothing in the browser (not even “No items found”, so I guess it is returning something I can’t see?).

This is the overall code as it was now, which only returns the cards that have the same primary tag, is there something I’m missing?

Edit: I tried pasting the full code including html, but that removed the html attributes… added a screenshot instead.

You might make better progress with using the code from the tutorial and working from there? In the tutorial it uses as |featured| within the #get helper, I believe this is needed to prevent identifier collisions with posts which may already exist on the page.