Get random posts from specific tags


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


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

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



Anyone ? :slight_smile:


@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.


OK thank you very much

closed #5

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.