Get random posts from specific tags


#1

I’m trying to display a limited number of posts randomly for a single tag or multiple tags.

EDIT:

        {{#get "posts" limit="2"  filter="tag:ubuntu"}}
           {{#foreach posts}}
              {{> "post-card"}}
           {{/foreach}}
        {{/get}}

I would like random posts, something like order="random", is it possible?

Thanks


#2

Anyone ? :slight_smile:


#3

@giacomosilli there is no random ordering available through handlebars or the API as it would not work how you expect due to multiple levels of caching - you’d likely end up with the same 2 posts shown consistently until something was changed which caused the cache to be rebuilt.

You could do something client-side using the Content API if you fetch a list of IDs for posts which match your filter and then randomly selecting a couple of those IDs to do full fetches.


#4

OK thank you very much