0

First of all, I haven't tried anything yet because I really don't know where to start.

I am trying to randomly display a post (from a CPT) based on a meta value (a numeric meta value from 1 to 10) which should act like a priority/weight. Higher the value is, higher the chance to display that post.

I believe this can not be achieved using standard WordPress loop and this is exactly where my researches are getting lost.

How can I do this? Any help or point of direction would be appreciated.

Thanks

1

hell yes you can do this with a standard WP_Query. As far as i understand, all you need is a random number between 1 and 10 (or so) and then fetch a random post with that specific number > meta_query. So all you need is a logic, that creates your random number, preferably the lower, the more often..

floor(abs(random() - random()) * (1 + max - min) + min)

credits

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.