Allow rand post ordering. Props Otto42 and Nazgul. fixes #4617

git-svn-id: http://svn.automattic.com/wordpress/trunk@6760 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-02-08 19:50:10 +00:00
parent 8fa3f8bb00
commit 9989d4c23e

View File

@ -1150,7 +1150,7 @@ class WP_Query {
$q['orderby'] = 'post_date '.$q['order'];
} else {
// Used to filter values
$allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order', 'parent', 'ID');
$allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand');
$q['orderby'] = urldecode($q['orderby']);
$q['orderby'] = addslashes_gpc($q['orderby']);
$orderby_array = explode(' ',$q['orderby']);
@ -1160,8 +1160,16 @@ class WP_Query {
for ($i = 0; $i < count($orderby_array); $i++) {
// Only allow certain values for safety
$orderby = $orderby_array[$i];
if ( !('menu_order' == $orderby || 'ID' == $orderby ))
$orderby = 'post_' . $orderby;
switch ($orderby) {
case 'menu_order':
case 'ID':
break;
case 'rand':
$orderby = 'RAND()';
break;
default:
$orderby = 'post_' . $orderby;
}
if ( in_array($orderby_array[$i], $allowed_keys) )
$q['orderby'] .= (($i == 0) ? '' : ',') . $orderby;
}