Allow random post ordering
|Reported by:||Otto42||Owned by:||ryan|
This change is to allow orderby=rand for all the post query functions.
In wp-includes, query.php, add "rand" to the list of $allowed_keys.
Modify this code
if ( 'menu_order' != $orderby ) $orderby = 'post_' . $orderby;
if ( 'menu_order' != $orderby && 'rand' != $orderby) $orderby = 'post_' . $orderby; if ('rand' == $orderby) $orderby = 'RAND()';`
This will allow the mysql "ORDER BY RAND()" to be used in querying posts. There are lots of potential uses for pulling random posts, and current plugins to do it always have to directly query the database for them, meaning that they break whenever the database structure changes. Providing this sort of functionality directly makes more sense.
Since this is a simple change that doesn't break anything and only adds minor functionality, I suggest getting it in quickly. Preferably trunk. I would submit a patch, but I can't right now and anyway it's a simple change.
Change History (14)
- Keywords 2nd-opinion removed
- Owner changed from anonymous to Nazgul
- Status changed from new to assigned