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

git-svn-id: https://develop.svn.wordpress.org/trunk@6760 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-02-08 19:50:10 +00:00
parent 271222c2f9
commit ef7fb4b35e
1 changed files with 11 additions and 3 deletions

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;
}