diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php
index 12e7dec..6da3b37 100644
a
|
b
|
class WP_Term_Query { |
98 | 98 | * @type string $orderby Field(s) to order terms by. Accepts term fields ('name', |
99 | 99 | * 'slug', 'term_group', 'term_id', 'id', 'description', 'parent'), |
100 | 100 | * 'count' for term taxonomy count, 'include' to match the |
101 | | * 'order' of the $include param, 'meta_value', 'meta_value_num', |
| 101 | * 'order' of the $include param, 'slug__in' to match the |
| 102 | * 'order' of the $slug param, 'meta_value', 'meta_value_num', |
102 | 103 | * the value of `$meta_key`, the array keys of `$meta_query`, or |
103 | 104 | * 'none' to omit the ORDER BY clause. Defaults to 'name'. |
104 | 105 | * @type string $order Whether to order terms in ascending or descending order. |
… |
… |
class WP_Term_Query { |
830 | 831 | } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) { |
831 | 832 | $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) ); |
832 | 833 | $orderby = "FIELD( t.term_id, $include )"; |
| 834 | } elseif ( 'slug__in' == $_orderby && ! empty( $this->query_vars['slug'] ) && is_array( $this->query_vars['slug'] ) ) { |
| 835 | $slugs = implode( "', '", array_map( 'sanitize_title', $this->query_vars['slug__in'] ) ); |
| 836 | $orderby = "FIELD( t.slug, '" . $slugs . "')"; |
833 | 837 | } elseif ( 'none' == $_orderby ) { |
834 | 838 | $orderby = ''; |
835 | 839 | } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) { |
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 417dce0..807ee84 100644
a
|
b
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
873 | 873 | // Map to proper WP_Query orderby param. |
874 | 874 | if ( isset( $query_args['orderby'] ) && isset( $request['orderby'] ) ) { |
875 | 875 | $orderby_mappings = array( |
876 | | 'id' => 'ID', |
877 | | 'include' => 'post__in', |
878 | | 'slug' => 'post_name', |
| 876 | 'id' => 'ID', |
| 877 | 'include' => 'post__in', |
| 878 | 'slug' => 'post_name', |
| 879 | 'included_slugs' => 'post_name__in', |
879 | 880 | ); |
880 | 881 | |
881 | 882 | if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2105 | 2106 | 'parent', |
2106 | 2107 | 'relevance', |
2107 | 2108 | 'slug', |
| 2109 | 'included_slugs', |
2108 | 2110 | 'title', |
2109 | 2111 | ), |
2110 | 2112 | ); |
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
index 0723022..6494071 100644
a
|
b
|
class WP_REST_Terms_Controller extends WP_REST_Controller { |
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
| 191 | if ( isset( $prepared_args['orderby'] ) && isset( $request['orderby'] ) ) { |
| 192 | $orderby_mappings = array( |
| 193 | 'included_slugs' => 'slug__in', |
| 194 | ); |
| 195 | |
| 196 | if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { |
| 197 | $prepared_args['orderby'] = $orderby_mappings[ $request['orderby'] ]; |
| 198 | } |
| 199 | } |
| 200 | |
191 | 201 | if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) { |
192 | 202 | $prepared_args['offset'] = $request['offset']; |
193 | 203 | } else { |
… |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller { |
930 | 940 | 'include', |
931 | 941 | 'name', |
932 | 942 | 'slug', |
| 943 | 'included_slugs', |
933 | 944 | 'term_group', |
934 | 945 | 'description', |
935 | 946 | 'count', |
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
index 5afe3a2..6ccf357 100644
a
|
b
|
class WP_REST_Users_Controller extends WP_REST_Controller { |
243 | 243 | 'name' => 'display_name', |
244 | 244 | 'registered_date' => 'registered', |
245 | 245 | 'slug' => 'user_nicename', |
| 246 | 'included_slugs' => 'nicename__in', |
246 | 247 | 'email' => 'user_email', |
247 | 248 | 'url' => 'user_url', |
248 | 249 | ); |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1324 | 1325 | 'name', |
1325 | 1326 | 'registered_date', |
1326 | 1327 | 'slug', |
| 1328 | 'included_slugs', |
1327 | 1329 | 'email', |
1328 | 1330 | 'url', |
1329 | 1331 | ), |
diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php
index fbf7d06..30b1a9c 100644
a
|
b
|
class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas |
287 | 287 | $this->assertEquals( 'Cantaloupe', $data[2]['name'] ); |
288 | 288 | } |
289 | 289 | |
| 290 | public function test_get_items_orderby_slugs() { |
| 291 | $this->factory->category->create( array( 'name' => 'Burrito' ) ); |
| 292 | $this->factory->category->create( array( 'name' => 'Taco' ) ); |
| 293 | $this->factory->category->create( array( 'name' => 'Chalupa' ) ); |
| 294 | |
| 295 | $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); |
| 296 | $request->set_param( 'orderby', 'included_slugs' ); |
| 297 | $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); |
| 298 | $response = $this->server->dispatch( $request ); |
| 299 | $data = $response->get_data(); |
| 300 | $this->assertEquals( 200, $response->get_status() ); |
| 301 | $this->assertEquals( 'taco', $data[0]['slug'] ); |
| 302 | $this->assertEquals( 'burrito', $data[1]['slug'] ); |
| 303 | $this->assertEquals( 'chalupa', $data[2]['slug'] ); |
| 304 | } |
| 305 | |
290 | 306 | protected function post_with_categories() { |
291 | 307 | $post_id = $this->factory->post->create(); |
292 | 308 | $category1 = $this->factory->category->create( array( |
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
index c86879c..650cafe 100644
a
|
b
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
598 | 598 | $this->assertPostsOrderedBy( '{posts}.post_name DESC' ); |
599 | 599 | } |
600 | 600 | |
| 601 | public function test_get_items_with_orderby_slugs() { |
| 602 | $slugs = array( 'burrito', 'taco', 'chalupa' ); |
| 603 | foreach ( $slugs as $slug ) { |
| 604 | $this->factory->post->create( array( 'post_title' => $slug, 'post_name' => $slug, 'post_status' => 'publish' ) ); |
| 605 | } |
| 606 | |
| 607 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); |
| 608 | $request->set_param( 'orderby', 'included_slugs' ); |
| 609 | $request->set_param( 'slug', array( 'taco', 'chalupa', 'burrito' ) ); |
| 610 | |
| 611 | $response = $this->server->dispatch( $request ); |
| 612 | $data = $response->get_data(); |
| 613 | |
| 614 | $this->assertEquals( 'taco', $data[0]['slug'] ); |
| 615 | $this->assertEquals( 'chalupa', $data[1]['slug'] ); |
| 616 | $this->assertEquals( 'burrito', $data[2]['slug'] ); |
| 617 | } |
| 618 | |
601 | 619 | public function test_get_items_with_orderby_relevance() { |
602 | 620 | $id1 = $this->factory->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish' ) ); |
603 | 621 | $id2 = $this->factory->post->create( array( 'post_title' => 'Title is', 'post_content' => 'Content is less relevant', 'post_status' => 'publish' ) ); |
diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php
index fccc4d7..a128590 100644
a
|
b
|
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
250 | 250 | $this->assertEquals( 'Cantaloupe', $data[2]['name'] ); |
251 | 251 | } |
252 | 252 | |
| 253 | public function test_get_items_orderby_slugs() { |
| 254 | $this->factory->tag->create( array( 'name' => 'Burrito' ) ); |
| 255 | $this->factory->tag->create( array( 'name' => 'Taco' ) ); |
| 256 | $this->factory->tag->create( array( 'name' => 'Chalupa' ) ); |
| 257 | |
| 258 | $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); |
| 259 | $request->set_param( 'orderby', 'included_slugs' ); |
| 260 | $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); |
| 261 | $response = $this->server->dispatch( $request ); |
| 262 | $data = $response->get_data(); |
| 263 | $this->assertEquals( 200, $response->get_status() ); |
| 264 | $this->assertEquals( 'taco', $data[0]['slug'] ); |
| 265 | $this->assertEquals( 'burrito', $data[1]['slug'] ); |
| 266 | $this->assertEquals( 'chalupa', $data[2]['slug'] ); |
| 267 | } |
| 268 | |
253 | 269 | public function test_get_items_post_args() { |
254 | 270 | $post_id = $this->factory->post->create(); |
255 | 271 | $tag1 = $this->factory->tag->create( array( 'name' => 'DC' ) ); |
diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php
index 3024693..6fdba3b 100644
a
|
b
|
class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { |
409 | 409 | $this->assertEquals( $low_id, $data[0]['id'] ); |
410 | 410 | } |
411 | 411 | |
| 412 | public function test_get_items_orderby_slugs() { |
| 413 | wp_set_current_user( self::$user ); |
| 414 | |
| 415 | $this->factory->user->create( array( 'user_nicename' => 'burrito' ) ); |
| 416 | $this->factory->user->create( array( 'user_nicename' => 'taco' ) ); |
| 417 | $this->factory->user->create( array( 'user_nicename' => 'chalupa' ) ); |
| 418 | |
| 419 | $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); |
| 420 | $request->set_param( 'orderby', 'included_slugs' ); |
| 421 | $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); |
| 422 | $response = $this->server->dispatch( $request ); |
| 423 | $data = $response->get_data(); |
| 424 | |
| 425 | $this->assertEquals( 'taco', $data[0]['slug'] ); |
| 426 | $this->assertEquals( 'burrito', $data[1]['slug'] ); |
| 427 | $this->assertEquals( 'chalupa', $data[2]['slug'] ); |
| 428 | } |
| 429 | |
412 | 430 | public function test_get_items_orderby_email() { |
413 | 431 | wp_set_current_user( self::$user ); |
414 | 432 | |
diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js
index 679d024..ebd91d7 100644
a
|
b
|
mockedApiResponse.Schema = { |
284 | 284 | "parent", |
285 | 285 | "relevance", |
286 | 286 | "slug", |
| 287 | "included_slugs", |
287 | 288 | "title" |
288 | 289 | ], |
289 | 290 | "description": "Sort collection by object attribute.", |
… |
… |
mockedApiResponse.Schema = { |
905 | 906 | "parent", |
906 | 907 | "relevance", |
907 | 908 | "slug", |
| 909 | "included_slugs", |
908 | 910 | "title", |
909 | 911 | "menu_order" |
910 | 912 | ], |
… |
… |
mockedApiResponse.Schema = { |
1443 | 1445 | "parent", |
1444 | 1446 | "relevance", |
1445 | 1447 | "slug", |
| 1448 | "included_slugs", |
1446 | 1449 | "title" |
1447 | 1450 | ], |
1448 | 1451 | "description": "Sort collection by object attribute.", |
… |
… |
mockedApiResponse.Schema = { |
2023 | 2026 | "include", |
2024 | 2027 | "name", |
2025 | 2028 | "slug", |
| 2029 | "included_slugs", |
2026 | 2030 | "term_group", |
2027 | 2031 | "description", |
2028 | 2032 | "count" |
… |
… |
mockedApiResponse.Schema = { |
2266 | 2270 | "include", |
2267 | 2271 | "name", |
2268 | 2272 | "slug", |
| 2273 | "included_slugs", |
2269 | 2274 | "term_group", |
2270 | 2275 | "description", |
2271 | 2276 | "count" |
… |
… |
mockedApiResponse.Schema = { |
2495 | 2500 | "name", |
2496 | 2501 | "registered_date", |
2497 | 2502 | "slug", |
| 2503 | "included_slugs", |
2498 | 2504 | "email", |
2499 | 2505 | "url" |
2500 | 2506 | ], |