mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
Query: Allow a seed value to be passed when using 'rand' $orderby.
`WP_Query` allows random ordering; `'orderby' => 'rand'` translates to `ORDER BY RAND()`. This syntax results in random ordering that is not consistent from request to request. MySQL supports the passing of a seed value to random sorts, such as `ORDER BY RAND(3)`, which will return the same random value each time it's called. `WP_Query` now supports this syntax, by passing `RAND(3)` (or whatever integer seed value you'd like) as the value of `'orderby'`. Props hlashbrooke. Fixes #35692. git-svn-id: https://develop.svn.wordpress.org/trunk@36632 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -303,6 +303,39 @@ class Tests_Post_Query extends WP_UnitTestCase {
|
||||
$this->assertNotContains( 'ASC', $q5->request );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35692
|
||||
*/
|
||||
public function test_orderby_rand_with_seed() {
|
||||
$q = new WP_Query( array(
|
||||
'orderby' => 'RAND(5)',
|
||||
) );
|
||||
|
||||
$this->assertContains( 'ORDER BY RAND(5)', $q->request );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35692
|
||||
*/
|
||||
public function test_orderby_rand_should_ignore_invalid_seed() {
|
||||
$q = new WP_Query( array(
|
||||
'orderby' => 'RAND(foo)',
|
||||
) );
|
||||
|
||||
$this->assertNotContains( 'ORDER BY RAND', $q->request );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35692
|
||||
*/
|
||||
public function test_orderby_rand_with_seed_should_be_case_insensitive() {
|
||||
$q = new WP_Query( array(
|
||||
'orderby' => 'rand(5)',
|
||||
) );
|
||||
|
||||
$this->assertContains( 'ORDER BY RAND(5)', $q->request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the post_name__in attribute of WP_Query.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user