I have 3 categories: A, B, C. A is having around 1000 posts, B has around 300 posts and C has 50 posts. When I query for 5 posts, ordered randomly. I get mostly posts from A category.
How can get mixed category random posts like 3 from A, 1 from B and 1 from C?
I whipped this up:
If any posts are in 2 or more of the selected categories there is a chance that a post will be repeated (like a post that is in both category A and category B). A static variable with an array of previously retrieved post might fix that.
This algorithm prints the posts in the order they were called.
If you want a random list, shuffle
$random_posts
.