Get random posts; a simple, more efficient approach.


MySQL queries that use ORDER BY RAND() can be pretty challenging and slow on large datasets. This function is an alternative method for getting random posts, though it’s not as good but at least it won’t destroy your site :).


Name Type Description
$number int Optional. Amount of random posts to get. Default 1.
$post_type string Optional. Specify the post_type to use when randomizing posts. Default 'post'.
$return_ids bool Optional. To just get the IDs, set this to true, otherwise post objects are returned (the default).

Return Value


Ready to get started?

Drop us a note.

No matter where you are in the planning process, we’re happy to help, and we’re actual humans here on the other side of the form. 👋 We’re here to discuss your challenges and plans, evaluate your existing resources or a potential partner, or even make some initial recommendations. And, of course, we’re here to help any time you’re in the market for some robust WordPress awesomeness.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.