I’ve implemented a simple related posts block. If there are other posts with a matching primary tag, I show related posts. If not, I show the latest posts.
{{#get "posts" limit="3" filter="primary_tag:{{primary_tag.slug}}+id:-{{id}}" include="authors,tags" as |related|}}
{{#if related}}
{{#foreach related}}
{{> card}}
{{/foreach}}
{{else}}
{{#get "posts" limit="3" filter="id:-{{id}}" include="authors,tags" as |latest|}}
{{#foreach latest}}
{{> card}}
{{/foreach}}
{{/get}}
{{/if}}
{{/get}}
This works for related posts, but the latest posts only appear if I remove the filter. This isn’t ideal since I end up recommending the same post you’re currently reading.
I feel like it’s a simple solve, but I’m not sure what I’m doing wrong here. Appreciate any help!