diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php
index 12e7dec242..f7ea039a83 100644
a
|
b
|
class WP_Term_Query { |
99 | 99 | * 'slug', 'term_group', 'term_id', 'id', 'description', 'parent'), |
100 | 100 | * 'count' for term taxonomy count, 'include' to match the |
101 | 101 | * 'order' of the $include param, 'meta_value', 'meta_value_num', |
102 | | * the value of `$meta_key`, the array keys of `$meta_query`, or |
103 | | * 'none' to omit the ORDER BY clause. Defaults to 'name'. |
| 102 | * the value of `$meta_key`, the array keys of `$meta_query`, 'rand' |
| 103 | * for a random selection, or 'none' to omit the ORDER BY clause. |
| 104 | * Defaults to 'name'. |
104 | 105 | * @type string $order Whether to order terms in ascending or descending order. |
105 | 106 | * Accepts 'ASC' (ascending) or 'DESC' (descending). |
106 | 107 | * Default 'ASC'. |
… |
… |
class WP_Term_Query { |
834 | 835 | $orderby = ''; |
835 | 836 | } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) { |
836 | 837 | $orderby = 't.term_id'; |
837 | | } else { |
| 838 | } elseif ( 'rand' === $_orderby ) { |
| 839 | $orderby = 'rand()'; |
| 840 | } else { |
838 | 841 | $orderby = 't.name'; |
839 | 842 | |
840 | 843 | // This may be a value of orderby related to meta. |
diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php
index b2e2a27621..c2ad5aab0a 100644
a
|
b
|
class Tests_Term_Query extends WP_UnitTestCase { |
143 | 143 | return $clauses; |
144 | 144 | } |
145 | 145 | |
| 146 | /** |
| 147 | * @ticket 41350 |
| 148 | */ |
| 149 | public function test_order_by_rand() { |
| 150 | $q = new WP_Term_Query( array( |
| 151 | 'taxonomy' => array( 'wptests_tax' ), |
| 152 | 'orderby' => 'rand', |
| 153 | 'hide_empty' => false, |
| 154 | ) ); |
| 155 | $this->assertContains( 'ORDER BY rand()', $q->request ); |
| 156 | } |
| 157 | |
146 | 158 | /** |
147 | 159 | * @ticket 37198 |
148 | 160 | */ |