Primary_tag not usable inside #get / #foreach

Hi!
I’m working on a “related posts” section in my blog tht is supposed to show a few articles from the same primary tag. To introduce that section I want a section that reads “Read more about <primary_tag>:”.

It seems like when I’m inside the #get context, and/or the #foreach context inside the #get, I don’t have access to the posts’ primary tags? The posts I’m testing this on have primary tags and the #get post filter filters correctly, it’s just inside that I cannot address the primary tag, I’m just getting “Read more about :”.

I must be doing something obvious wrong, this seems pretty basic to me?

{{#get "posts" filter="primary_tag:{{primary_tag.slug}}+id:-{{id}}" limit="6"}}
    {{#foreach posts}}
        {{#has number="1"}}
        <h3 class="align-center">Read more about <a href="{{primary_tag.url}}">{{primary_tag.name}}</a>:</h3>
        {{/has}}
        <article>
            <h4>{{title}}</4p>
            {{#if feature_image}}
            <img src="{{feature_image}}">
            {{/if}}
        </article>
    {{/foreach}}
{{/get}}

By default, the response from the {{get}} will only contain base data from post resource.
You have to use the include parameter to load tags (same for authors):

{{#get "posts" include="tags" filter="primary_tag:{{primary_tag.slug}}+id:-{{id}}" limit="6"}}

This way you should have access to the tags within the foreach.

3 Likes

This was driving me nuts - thanks bironthemes!

1 Like