Changeset 39093
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r39089 r39093 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 ); … … 883 883 'posts_per_page', 884 884 'date_query', 885 'post_name__in', 885 886 ); 886 887 … … 2113 2114 2114 2115 $params['slug'] = array( 2115 'description' => __( 'Limit result set to posts with a specific slug.' ),2116 'type' => ' string',2117 ' validate_callback' => 'rest_validate_request_arg',2116 'description' => __( 'Limit result set to posts with one or more specific slugs.' ), 2117 'type' => 'array', 2118 'sanitize_callback' => 'wp_parse_slug_list', 2118 2119 ); 2119 2120 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r39084 r39093 253 253 $this->assertEquals( 1, count( $data ) ); 254 254 $this->assertEquals( 'Apple', $data[0]['title']['rendered'] ); 255 } 256 257 public function test_get_items_multiple_slugs_array_query() { 258 $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) ); 259 $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) ); 260 $this->factory->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish' ) ); 261 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 262 $request->set_param( 'slug', array( 'banana', 'peach' ) ); 263 $response = $this->server->dispatch( $request ); 264 $this->assertEquals( 200, $response->get_status() ); 265 $data = $response->get_data(); 266 $this->assertEquals( 2, count( $data ) ); 267 $titles = array( 268 $data[0]['title']['rendered'], 269 $data[1]['title']['rendered'], 270 ); 271 sort( $titles ); 272 $this->assertEquals( array( 'Banana', 'Peach' ), $titles ); 273 } 274 275 public function test_get_items_multiple_slugs_string_query() { 276 $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) ); 277 $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) ); 278 $this->factory->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish' ) ); 279 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 280 $request->set_param( 'slug', 'apple,banana' ); 281 $response = $this->server->dispatch( $request ); 282 $this->assertEquals( 200, $response->get_status() ); 283 $data = $response->get_data(); 284 $this->assertEquals( 2, count( $data ) ); 285 $titles = array( 286 $data[0]['title']['rendered'], 287 $data[1]['title']['rendered'], 288 ); 289 sort( $titles ); 290 $this->assertEquals( array( 'Apple', 'Banana' ), $titles ); 255 291 } 256 292
Note: See TracChangeset
for help on using the changeset viewer.