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.



git-svn-id: https://develop.svn.wordpress.org/trunk@41760 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
K. Adam White
2017-10-05 00:36:43 +00:00
parent 75ce48ef70
commit 8cda3a2f55
9 changed files with 98 additions and 4 deletions

View File

@@ -874,9 +874,10 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
// Map to proper WP_Query orderby param.
if ( isset( $query_args['orderby'] ) && isset( $request['orderby'] ) ) {
$orderby_mappings = array(
'id' => 'ID',
'include' => 'post__in',
'slug' => 'post_name',
'id' => 'ID',
'include' => 'post__in',
'slug' => 'post_name',
'include_slugs' => 'post_name__in',
);
if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) {
@@ -2109,6 +2110,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
'parent',
'relevance',
'slug',
'include_slugs',
'title',
),
);