diff --git src/wp-includes/class-wp-term-query.php src/wp-includes/class-wp-term-query.php
index 74386bc9ab..c71735286e 100644
|
|
class WP_Term_Query { |
106 | 106 | * @type string $orderby Field(s) to order terms by. Accepts term fields ('name', |
107 | 107 | * 'slug', 'term_group', 'term_id', 'id', 'description'), |
108 | 108 | * 'count' for term taxonomy count, 'include' to match the |
109 | | * 'order' of the $include param, 'meta_value', 'meta_value_num', |
110 | | * the value of `$meta_key`, the array keys of `$meta_query`, or |
111 | | * 'none' to omit the ORDER BY clause. Defaults to 'name'. |
| 109 | * 'order' of the $include param, 'slugs' to match the 'order' |
| 110 | * of the $slug param (when it is an array), 'meta_value', |
| 111 | * 'meta_value_num', the value of `$meta_key`, the array keys |
| 112 | * of `$meta_query`, or 'none' to omit the ORDER BY clause. |
| 113 | * Defaults to 'name'. |
112 | 114 | * @type string $order Whether to order terms in ascending or descending order. |
113 | 115 | * Accepts 'ASC' (ascending) or 'DESC' (descending). |
114 | 116 | * Default 'ASC'. |
… |
… |
class WP_Term_Query { |
842 | 844 | } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) { |
843 | 845 | $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) ); |
844 | 846 | $orderby = "FIELD( t.term_id, $include )"; |
| 847 | } elseif ( 'slugs' == $_orderby && ! empty( $this->query_vars['slug'] ) && is_array( $this->query_vars['slug'] ) ) { |
| 848 | $slugs = implode( "', '", array_map( 'sanitize_title', $this->query_vars['slug'] ) ); |
| 849 | $orderby = "FIELD( t.slug, '" . $slugs . "')"; |
845 | 850 | } elseif ( 'none' == $_orderby ) { |
846 | 851 | $orderby = ''; |
847 | 852 | } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) { |
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 39593cbe3e..e03aaa6cdd 100644
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
892 | 892 | 'id' => 'ID', |
893 | 893 | 'include' => 'post__in', |
894 | 894 | 'slug' => 'post_name', |
| 895 | 'slugs' => 'post_name__in', |
895 | 896 | ); |
896 | 897 | |
897 | 898 | if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2138 | 2139 | 'parent', |
2139 | 2140 | 'relevance', |
2140 | 2141 | 'slug', |
| 2142 | 'slugs', |
2141 | 2143 | 'title', |
2142 | 2144 | ), |
2143 | 2145 | ); |
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
index 299b034329..3ec6e5f579 100644
|
|
class WP_REST_Terms_Controller extends WP_REST_Controller { |
951 | 951 | 'include', |
952 | 952 | 'name', |
953 | 953 | 'slug', |
| 954 | 'slugs', |
954 | 955 | 'term_group', |
955 | 956 | 'description', |
956 | 957 | 'count', |
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
index 63fb4e9e99..bfbea9a295 100644
|
|
class WP_REST_Users_Controller extends WP_REST_Controller { |
249 | 249 | 'name' => 'display_name', |
250 | 250 | 'registered_date' => 'registered', |
251 | 251 | 'slug' => 'user_nicename', |
| 252 | 'slugs' => 'nicename__in', |
252 | 253 | 'email' => 'user_email', |
253 | 254 | 'url' => 'user_url', |
254 | 255 | ); |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1351 | 1352 | 'name', |
1352 | 1353 | 'registered_date', |
1353 | 1354 | 'slug', |
| 1355 | 'slugs', |
1354 | 1356 | 'email', |
1355 | 1357 | 'url', |
1356 | 1358 | ), |
diff --git tests/phpunit/tests/rest-api/rest-categories-controller.php tests/phpunit/tests/rest-api/rest-categories-controller.php
index fbf7d06018..e9b70ca075 100644
|
|
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', '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 tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
index c86879cffc..889eee77a8 100644
|
|
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', '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 tests/phpunit/tests/rest-api/rest-tags-controller.php tests/phpunit/tests/rest-api/rest-tags-controller.php
index fccc4d702d..9c2f5613ab 100644
|
|
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', '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 tests/phpunit/tests/rest-api/rest-users-controller.php tests/phpunit/tests/rest-api/rest-users-controller.php
index 44853aa13a..9f17882d54 100644
|
|
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', '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 tests/qunit/fixtures/wp-api-generated.js tests/qunit/fixtures/wp-api-generated.js
index 69e2375563..38086a9dbc 100644
|
|
mockedApiResponse.Schema = { |
284 | 284 | "parent", |
285 | 285 | "relevance", |
286 | 286 | "slug", |
| 287 | "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 | "slugs", |
908 | 910 | "title", |
909 | 911 | "menu_order" |
910 | 912 | ], |
… |
… |
mockedApiResponse.Schema = { |
1443 | 1445 | "parent", |
1444 | 1446 | "relevance", |
1445 | 1447 | "slug", |
| 1448 | "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 | "slugs", |
2026 | 2030 | "term_group", |
2027 | 2031 | "description", |
2028 | 2032 | "count" |
… |
… |
mockedApiResponse.Schema = { |
2266 | 2270 | "include", |
2267 | 2271 | "name", |
2268 | 2272 | "slug", |
| 2273 | "slugs", |
2269 | 2274 | "term_group", |
2270 | 2275 | "description", |
2271 | 2276 | "count" |
… |
… |
mockedApiResponse.Schema = { |
2495 | 2500 | "name", |
2496 | 2501 | "registered_date", |
2497 | 2502 | "slug", |
| 2503 | "slugs", |
2498 | 2504 | "email", |
2499 | 2505 | "url" |
2500 | 2506 | ], |