[wp-trac] [WordPress Trac] #4617: Allow random post ordering

WordPress Trac wp-trac at lists.automattic.com
Wed Jul 11 20:47:28 GMT 2007

#4617: Allow random post ordering
 Reporter:  Otto42       |       Owner:  anonymous  
     Type:  enhancement  |      Status:  new        
 Priority:  normal       |   Milestone:  2.3 (trunk)
Component:  Template     |     Version:  2.2.1      
 Severity:  normal       |    Keywords:             
 This change is to allow orderby=rand for all the post query functions.

 Changes needed:
 In wp-includes, query.php, add "rand" to the list of $allowed_keys.

 Modify this code
 if ( 'menu_order' != $orderby )
 $orderby = 'post_' . $orderby;

 into this:
 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

Ticket URL: <http://trac.wordpress.org/ticket/4617>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list