So I was trying to fetch random items from the API but I don't find any way.
As a workaround, we fetch all items and then only pick a few of them.
This is far from ideal, but can't find any other solution.
Is it possible to fetch random items from Prismic?
Thanks for this question! It's an interesting use case. I would get the total number of docs in the repo with a general query, then generate a random number between 1 and the total, and then grab a doc at that index using API pagination. Here's a repl showing how that could work:
Let me know if that makes sense, or if you have any other questions
Personally, I would go ahead and make the four requests in parallel. They will probably use the same ref, so the data will be cached and the requests will be extremely fast. Though, I see what you mean that it is a little ugly, and you'll need to guard against duplicates.
In any case, I'll change this to a feature request for orderings=random, and submit it to our product team.
Sam
2 Likes
samlittlefair
(Sam Littlefair)
closed , flag & select 'Something Else' to reopen.
6