diff --git a/lib/endpoints/class-wp-rest-terms-controller.php b/lib/endpoints/class-wp-rest-terms-controller.php index c746af48b1..18d3776c8b 100755 --- a/lib/endpoints/class-wp-rest-terms-controller.php +++ b/lib/endpoints/class-wp-rest-terms-controller.php @@ -69,6 +69,7 @@ public function register_routes() { */ public function get_items( $request ) { $prepared_args = array( + 'include' => $request['include'], 'order' => $request['order'], 'orderby' => $request['orderby'], 'hide_empty' => $request['hide_empty'], @@ -577,6 +578,12 @@ public function get_collection_params() { $query_params['context']['default'] = 'view'; + $query_params['include'] = array( + 'description' => __( 'Limit result set to specific ids.' ), + 'type' => 'array', + 'default' => array(), + 'sanitize_callback' => 'wp_parse_id_list', + ); $query_params['order'] = array( 'description' => __( 'Order sort attribute ascending or descending.' ), 'type' => 'string', @@ -594,6 +601,7 @@ public function get_collection_params() { 'default' => 'name', 'enum' => array( 'id', + 'include', 'name', 'slug', 'term_group', diff --git a/tests/test-rest-terms-controller.php b/tests/test-rest-terms-controller.php index 1176f5cbf8..fb58893c48 100644 --- a/tests/test-rest-terms-controller.php +++ b/tests/test-rest-terms-controller.php @@ -51,6 +51,7 @@ public function test_registered_query_params() { $this->assertEquals( array( 'context', 'hide_empty', + 'include', 'order', 'orderby', 'page', @@ -152,6 +153,25 @@ public function test_get_items_by_parent_non_found() { $this->assertEquals( array(), $data ); } + public function test_get_items_include_query() { + $id1 = $this->factory->tag->create(); + $id2 = $this->factory->tag->create(); + $id3 = $this->factory->tag->create(); + $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); + // Orderby=>asc + $request->set_param( 'include', array( $id3, $id1 ) ); + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $this->assertEquals( 2, count( $data ) ); + $this->assertEquals( $id1, $data[0]['id'] ); + // Orderby=>include + $request->set_param( 'orderby', 'include' ); + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $this->assertEquals( 2, count( $data ) ); + $this->assertEquals( $id3, $data[0]['id'] ); + } + public function test_get_items_orderby_args() { $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) );