diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index e0cdc79a2f..872a6607cb 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -148,6 +148,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) ); } + // Ensure an include parameter is set in case the orderby is set to 'include'. + if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) { + return new WP_Error( 'rest_orderby_include_missing_include', sprintf( __( 'Missing parameter(s): %s' ), 'include' ), array( 'status' => 400 ) ); + } + // Retrieve the list of registered collection query parameters. $registered = $this->get_collection_params(); $args = array(); @@ -836,8 +841,17 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $query_args['ignore_sticky_posts'] = true; } - if ( 'include' === $query_args['orderby'] ) { - $query_args['orderby'] = 'post__in'; + // 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', + ); + + if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { + $query_args['orderby'] = $orderby_mappings[ $request['orderby'] ]; + } } return $query_args; diff --git a/wp-includes/version.php b/wp-includes/version.php index c41f042978..1880cc2598 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-RC1-39439'; +$wp_version = '4.7-RC1-39441'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.