Ticket #38579: 38579.diff
File 38579.diff, 3.6 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index a9d8f3c..6186d64 100644
a b class WP_REST_Posts_Controller extends WP_REST_Controller { 169 169 'parent' => 'post_parent__in', 170 170 'parent_exclude' => 'post_parent__not_in', 171 171 'search' => 's', 172 'slug' => ' name',172 'slug' => 'post_name__in', 173 173 'status' => 'post_status', 174 174 ); 175 175 … … class WP_REST_Posts_Controller extends WP_REST_Controller { 890 890 'post_parent__not_in', 891 891 'posts_per_page', 892 892 'date_query', 893 'post_name__in', 893 894 ); 894 895 895 896 $valid_vars = array_merge( $valid_vars, $rest_valid ); … … class WP_REST_Posts_Controller extends WP_REST_Controller { 2100 2101 } 2101 2102 2102 2103 $params['slug'] = array( 2103 'description' => __( 'Limit result set to posts with a specific slug.' ),2104 'type' => ' string',2105 ' validate_callback' => 'rest_validate_request_arg',2104 'description' => __( 'Limit result set to posts with one or more specific slugs.' ), 2105 'type' => 'array', 2106 'sanitize_callback' => 'wp_parse_slug_list', 2106 2107 ); 2107 2108 2108 2109 $params['status'] = array( -
tests/phpunit/tests/rest-api/rest-posts-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 3365f77..1123232 100644
a b class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 234 234 $this->assertEquals( 'Apple', $data[0]['title']['rendered'] ); 235 235 } 236 236 237 public function test_get_items_multiple_slugs_array_query() { 238 $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) ); 239 $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) ); 240 $this->factory->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish' ) ); 241 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 242 $request->set_param( 'slug', array( 'banana', 'peach' ) ); 243 $response = $this->server->dispatch( $request ); 244 $this->assertEquals( 200, $response->get_status() ); 245 $data = $response->get_data(); 246 $this->assertEquals( 2, count( $data ) ); 247 $titles = array( 248 $data[0]['title']['rendered'], 249 $data[1]['title']['rendered'], 250 ); 251 sort( $titles ); 252 $this->assertEquals( array( 'Banana', 'Peach' ), $titles ); 253 } 254 255 public function test_get_items_multiple_slugs_string_query() { 256 $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) ); 257 $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) ); 258 $this->factory->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish' ) ); 259 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 260 $request->set_param( 'slug', 'apple,banana' ); 261 $response = $this->server->dispatch( $request ); 262 $this->assertEquals( 200, $response->get_status() ); 263 $data = $response->get_data(); 264 $this->assertEquals( 2, count( $data ) ); 265 $titles = array( 266 $data[0]['title']['rendered'], 267 $data[1]['title']['rendered'], 268 ); 269 sort( $titles ); 270 $this->assertEquals( array( 'Apple', 'Banana' ), $titles ); 271 } 272 237 273 public function test_get_items_status_query() { 238 274 wp_set_current_user( 0 ); 239 275 $this->factory->post->create( array( 'post_status' => 'draft' ) );