diff --git a/wp-includes/class-wp-term-query.php b/wp-includes/class-wp-term-query.php index f6f53f210c..9a9b902dea 100644 --- a/wp-includes/class-wp-term-query.php +++ b/wp-includes/class-wp-term-query.php @@ -87,6 +87,7 @@ class WP_Term_Query { * @since 4.6.0 * @since 4.6.0 Introduced 'term_taxonomy_id' parameter. * @since 4.7.0 Introduced 'object_ids' parameter. + * @since 4.9.0 Added 'slug__in' support for 'orderby'. * * @param string|array $query { * Optional. Array or query string of term query parameters. Default empty. @@ -98,7 +99,8 @@ class WP_Term_Query { * @type string $orderby Field(s) to order terms by. Accepts term fields ('name', * 'slug', 'term_group', 'term_id', 'id', 'description', 'parent'), * 'count' for term taxonomy count, 'include' to match the - * 'order' of the $include param, 'meta_value', 'meta_value_num', + * 'order' of the $include param, 'slug__in' to match the + * 'order' of the $slug param, 'meta_value', 'meta_value_num', * the value of `$meta_key`, the array keys of `$meta_query`, or * 'none' to omit the ORDER BY clause. Defaults to 'name'. * @type string $order Whether to order terms in ascending or descending order. @@ -841,6 +843,9 @@ class WP_Term_Query { } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) { $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) ); $orderby = "FIELD( t.term_id, $include )"; + } elseif ( 'slug__in' == $_orderby && ! empty( $this->query_vars['slug'] ) && is_array( $this->query_vars['slug'] ) ) { + $slugs = implode( "', '", array_map( 'sanitize_title_for_query', $this->query_vars['slug__in'] ) ); + $orderby = "FIELD( t.slug, '" . $slugs . "')"; } elseif ( 'none' == $_orderby ) { $orderby = ''; } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) { 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 8d65252537..93a2b8db0d 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 @@ -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', ), ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 826902a164..749a6d6870 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -188,6 +188,16 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { } } + if ( isset( $prepared_args['orderby'] ) && isset( $request['orderby'] ) ) { + $orderby_mappings = array( + 'include_slugs' => 'slug__in', + ); + + if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { + $prepared_args['orderby'] = $orderby_mappings[ $request['orderby'] ]; + } + } + if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) { $prepared_args['offset'] = $request['offset']; } else { @@ -932,6 +942,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { 'include', 'name', 'slug', + 'include_slugs', 'term_group', 'description', 'count', diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index 44d6367a54..c7c32a73db 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -243,6 +243,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'name' => 'display_name', 'registered_date' => 'registered', 'slug' => 'user_nicename', + 'include_slugs' => 'nicename__in', 'email' => 'user_email', 'url' => 'user_url', ); @@ -1338,6 +1339,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'name', 'registered_date', 'slug', + 'include_slugs', 'email', 'url', ), diff --git a/wp-includes/version.php b/wp-includes/version.php index 6917766e26..c9783b2ef7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-41759'; +$wp_version = '4.9-alpha-41760'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.