Identifying primary-tagged posts on a tag archive

Hi,

I’m modifying my tag archive to achieve the following:

  1. posts that have the current tag as primary tag and are featured are pulled first (via a {{#get}} with the appropriate filter)
  2. Then, all the remaining posts are pulled in reverse chronological order via the normal data context of the tag archive.

However, in 2., I want to avoid repeating the prioritized posts I pulled in 1. What I’ve tried so far is putting an {{#if featured}} in the foreach loop and only printing the post for {{else}}, but that also eliminates all posts that are featured, but don’t have this tag as their primary tag.

Is there a way to achieve this? Or is there a different tagging / filtering logic I could use to achieve this?

Thanks!

I don’t think you can do it with the foreach helper.
You can do a second {{get}}, like this:

{{#get "posts" filter="primary_tag:{{tag.slug}}+featured:false,tags:{{tag.slug}}+primary_tag:-{{tag.slug}}"}}

How this works:

  • primary_tag:{{tag.slug}}+featured:false fetch posts where the primary tag is your tag and post is not featured
  • tags:{{tag.slug}}+primary_tag:-{{tag.slug}} fetch posts where the tag is not primary

Wow, thank you! That should work for me.

I was under the impression that filtering only works based on primary_tag - at least that’s what the documentation seemed to explicitly state.

I feel like

may be a somewhat undocumented feature… Is there any way to make this go into the official docs? This could have literally saved me 3 hours of fiddling (plus your time) if it was even just briefly mentioned as a possibility in the docs.