Make WordPress Core


Ignore:
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        if ( isset( $prepared_args['orderby'] ) && isset( $request['orderby'] ) ) {
     192            $orderby_mappings = array(
     193                'include_slugs' => 'slug__in',
     194            );
     195
     196            if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) {
     197                $prepared_args['orderby'] = $orderby_mappings[ $request['orderby'] ];
    188198            }
    189199        }
     
    933943                'name',
    934944                'slug',
     945                'include_slugs',
    935946                'term_group',
    936947                'description',
Note: See TracChangeset for help on using the changeset viewer.