Small filtering puzzle

Hello All!!

Can any of you assist me with the following objective?

  1. I need to display 2 lists. 1 List of posts tagged as “popular”, and another list of featured posts.
  2. Is there any specific approach that any of you know that I could make use of so I don’t occasionally display the same post in those 2 lists at the same time?

Here’s some pseudo code illustrating what I need

{{#get
    "posts"
    order="published_at desc"
    include="authors"
    filter="tag:most-popular"
    limit="2"
    filter=""
}}
    {{#foreach posts}}
        {{> "post-feature-small"}}
    {{/foreach}}
{{/get}}

.....

{{#get
    "posts"
    order="published_at desc"
    include="authors"
    filter="featured:true"
    limit="2"
    filter="THIS-IS-LIKELY-THE-PLACE-WHERE-THE-MAGIC-WILL-HAPPEN"
}}
    {{#foreach posts}}
        {{> "post-feature-small"}}
    {{/foreach}}
{{/get}}

Hi @jeandcc!

  1. Is there any specific approach that any of you know that I could make use of so I don’t occasionally display the same post in those 2 lists at the same time?

You can mutually exclude them as in the example below.

{{#get
    "posts"
    order="published_at desc"
    include="authors"
    filter="featured:false+tag:most-popular"
    limit="2"
}}
    {{#foreach posts}}
        {{> "post-feature-small"}}
    {{/foreach}}
{{/get}}

.....

{{#get
    "posts"
    order="published_at desc"
    include="authors"
    filter="featured:true+tag:-[most-popular]"
    limit="2"
}}
    {{#foreach posts}}
        {{> "post-feature-small"}}
    {{/foreach}}
{{/get}}
1 Like

This is perfect @fueko !! I will give it a try the soonest I can, and mark it as a solution!!

This seems pretty aligned with what I saw in the docs, thank you for helping out!!

I guess the lack of an example with “-[value]” in the docs is what got me insecure about this.

I appreciate you taking the time! Thanks!!

1 Like

@fueko , When I think of it… Even though this a great V1 for a solution, I wonder if there’s an acceptable/easy way to improve this even more.

In the second filter, do you think there is a way to filter out based on the posts that came in after the first get request?

Here’s an example: suppose I have 3 posts tagged as “most-popular”, but I only fetch two at the top. The one that wasn’t fetched is also marked as “featured”. That being the case, the third post should then go into the “featured posts” section.

Does this make sense? I wonder if nesting those get requests would allow us to do something?

Does this make sense?

The easiest way would be to set the filter in the second {{get}} request to filter="featured:true". But I understand that then the filtering would not always do what you expect.

I wonder if nesting those get requests would allow us to do something? In the second filter, do you think there is a way to filter out based on the posts that came in after the first get request?

In Ghost we try not to nest {{get}} requests, they may cause some problems. Perhaps someone with more knowledge will be able to advise you better here.