Monthly Archives: December 2011

Consistent Random Set Of Posts

A recent post on the WP support forum asked how to retrieve posts randomly, but be consistent when paginating.  In other words, the same random set would be shown on page 1 even after switching to a different page and back again.

The answer to this is to use a filter on the query to replace the ‘ORDER BY’ clause.  The MySQL RAND() function allows a seed value to the function.  Every time the same seed is supplied, the same set of rows will be retrieved for a given query. Continue reading