mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-18 04:25:07 +00:00
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:
parent
8fa3f8bb00
commit
9989d4c23e
@ -1150,7 +1150,7 @@ class WP_Query {
|
|||||||
$q['orderby'] = 'post_date '.$q['order'];
|
$q['orderby'] = 'post_date '.$q['order'];
|
||||||
} else {
|
} else {
|
||||||
// Used to filter values
|
// 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'] = urldecode($q['orderby']);
|
||||||
$q['orderby'] = addslashes_gpc($q['orderby']);
|
$q['orderby'] = addslashes_gpc($q['orderby']);
|
||||||
$orderby_array = explode(' ',$q['orderby']);
|
$orderby_array = explode(' ',$q['orderby']);
|
||||||
@ -1160,8 +1160,16 @@ class WP_Query {
|
|||||||
for ($i = 0; $i < count($orderby_array); $i++) {
|
for ($i = 0; $i < count($orderby_array); $i++) {
|
||||||
// Only allow certain values for safety
|
// Only allow certain values for safety
|
||||||
$orderby = $orderby_array[$i];
|
$orderby = $orderby_array[$i];
|
||||||
if ( !('menu_order' == $orderby || 'ID' == $orderby ))
|
switch ($orderby) {
|
||||||
$orderby = 'post_' . $orderby;
|
case 'menu_order':
|
||||||
|
case 'ID':
|
||||||
|
break;
|
||||||
|
case 'rand':
|
||||||
|
$orderby = 'RAND()';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$orderby = 'post_' . $orderby;
|
||||||
|
}
|
||||||
if ( in_array($orderby_array[$i], $allowed_keys) )
|
if ( in_array($orderby_array[$i], $allowed_keys) )
|
||||||
$q['orderby'] .= (($i == 0) ? '' : ',') . $orderby;
|
$q['orderby'] .= (($i == 0) ? '' : ',') . $orderby;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user