Make WordPress Core

Changeset 41760

Timestamp:
10/05/2017 12:36:43 AM (7 years ago)
Author:
kadamwhite
Message:

REST API: Support ordering response collection by listed slugs.

Adds an "include_slug" orderby value for REST API collections to permit returning a collection filtered by slugs in the same order in which those slugs are specified.
Previously, the order of slugs provided with the ?slug query parameter had no effect on the order of the returned records.

Props wonderboymusic, ocean90, boonebgorges.
Fixes #40826.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term-query.php

    r41377 r41760  
    8888     * @since 4.6.0 Introduced 'term_taxonomy_id' parameter.
    8989     * @since 4.7.0 Introduced 'object_ids' parameter.
     90
    9091     *
    9192     * @param string|array $query {
     
    99100     *                                                'slug', 'term_group', 'term_id', 'id', 'description', 'parent'),
    100101     *                                                'count' for term taxonomy count, 'include' to match the
    101      *                                                'order' of the $include param, 'meta_value', 'meta_value_num',
     102     *                                                'order' of the $include param, 'slug__in' to match the
     103     *                                                'order' of the $slug param, 'meta_value', 'meta_value_num',
    102104     *                                                the value of `$meta_key`, the array keys of `$meta_query`, or
    103105     *                                                'none' to omit the ORDER BY clause. Defaults to 'name'.
     
    842844            $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) );
    843845            $orderby = "FIELD( t.term_id, $include )";
     846
     847
     848
    844849        } elseif ( 'none' == $_orderby ) {
    845850            $orderby = '';
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r41731 r41760  
    875875        if ( isset( $query_args['orderby'] ) && isset( $request['orderby'] ) ) {
    876876            $orderby_mappings = array(
    877                 'id'      => 'ID',
    878                 'include' => 'post__in',
    879                 'slug'    => 'post_name',
     877                'id'            => 'ID',
     878                'include'       => 'post__in',
     879                'slug'          => 'post_name',
     880                'include_slugs' => 'post_name__in',
    880881            );
    881882
     
    21102111                'relevance',
    21112112                'slug',
     2113
    21122114                'title',
    21132115            ),
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r41737 r41760  
    186186            if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {
    187187                $prepared_args[ $wp_param ] = $request[ $api_param ];
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
    188198            }
    189199        }
     
    933943                'name',
    934944                'slug',
     945
    935946                'term_group',
    936947                'description',
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r41731 r41760  
    244244                'registered_date' => 'registered',
    245245                'slug'            => 'user_nicename',
     246
    246247                'email'           => 'user_email',
    247248                'url'             => 'user_url',
     
    13391340                'registered_date',
    13401341                'slug',
     1342
    13411343                'email',
    13421344                'url',
  • trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php

    r41737 r41760  
    288288    }
    289289
     290
     291
     292
     293
     294
     295
     296
     297
     298
     299
     300
     301
     302
     303
     304
     305
    290306    protected function post_with_categories() {
    291307        $post_id = $this->factory->post->create();
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r40605 r41760  
    597597        $this->assertEquals( 'abc', $data[1]['slug'] );
    598598        $this->assertPostsOrderedBy( '{posts}.post_name DESC' );
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
    599617    }
    600618
  • trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php

    r40376 r41760  
    249249        $this->assertEquals( 'Apple', $data[1]['name'] );
    250250        $this->assertEquals( 'Cantaloupe', $data[2]['name'] );
     251
     252
     253
     254
     255
     256
     257
     258
     259
     260
     261
     262
     263
     264
     265
     266
    251267    }
    252268
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r41226 r41760  
    408408        $data = $response->get_data();
    409409        $this->assertEquals( $low_id, $data[0]['id'] );
     410
     411
     412
     413
     414
     415
     416
     417
     418
     419
     420
     421
     422
     423
     424
     425
     426
     427
    410428    }
    411429
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r41678 r41760  
    285285                                "relevance",
    286286                                "slug",
     287
    287288                                "title"
    288289                            ],
     
    906907                                "relevance",
    907908                                "slug",
     909
    908910                                "title",
    909911                                "menu_order"
     
    14441446                                "relevance",
    14451447                                "slug",
     1448
    14461449                                "title"
    14471450                            ],
     
    20242027                                "name",
    20252028                                "slug",
     2029
    20262030                                "term_group",
    20272031                                "description",
     
    22672271                                "name",
    22682272                                "slug",
     2273
    22692274                                "term_group",
    22702275                                "description",
     
    24962501                                "registered_date",
    24972502                                "slug",
     2503
    24982504                                "email",
    24992505                                "url"
Note: See TracChangeset for help on using the changeset viewer.