REST API: Allow fetching multiple terms at once via the `slug` parameter.
This matches a similar change previously made for posts (#38579) and an upcoming change for users (#40213). Props wonderboymusic, MatheusGimenez, curdin. Fixes #40027. git-svn-id: https://develop.svn.wordpress.org/trunk@40376 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
54eb8900dd
commit
99de5d69d7
|
@ -978,7 +978,10 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
||||||
|
|
||||||
$query_params['slug'] = array(
|
$query_params['slug'] = array(
|
||||||
'description' => __( 'Limit result set to terms with a specific slug.' ),
|
'description' => __( 'Limit result set to terms with a specific slug.' ),
|
||||||
'type' => 'string',
|
'type' => 'array',
|
||||||
|
'items' => array(
|
||||||
|
'type' => 'string'
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -378,6 +378,40 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||||
$this->assertEquals( 'Apple', $data[0]['name'] );
|
$this->assertEquals( 'Apple', $data[0]['name'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_get_items_slug_array_arg() {
|
||||||
|
$id1 = $this->factory->tag->create( array( 'name' => 'Taco' ) );
|
||||||
|
$id2 = $this->factory->tag->create( array( 'name' => 'Enchilada' ) );
|
||||||
|
$id3 = $this->factory->tag->create( array( 'name' => 'Burrito' ) );
|
||||||
|
$this->factory->tag->create( array( 'name' => 'Pizza' ) );
|
||||||
|
$request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
|
||||||
|
$request->set_param( 'slug', array(
|
||||||
|
'taco',
|
||||||
|
'burrito',
|
||||||
|
'enchilada',
|
||||||
|
) );
|
||||||
|
$response = $this->server->dispatch( $request );
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$data = $response->get_data();
|
||||||
|
$names = wp_list_pluck( $data, 'name' );
|
||||||
|
sort( $names );
|
||||||
|
$this->assertEquals( array( 'Burrito', 'Enchilada', 'Taco' ), $names );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_items_slug_csv_arg() {
|
||||||
|
$id1 = $this->factory->tag->create( array( 'name' => 'Taco' ) );
|
||||||
|
$id2 = $this->factory->tag->create( array( 'name' => 'Enchilada' ) );
|
||||||
|
$id3 = $this->factory->tag->create( array( 'name' => 'Burrito' ) );
|
||||||
|
$this->factory->tag->create( array( 'name' => 'Pizza' ) );
|
||||||
|
$request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
|
||||||
|
$request->set_param( 'slug', 'taco,burrito, enchilada');
|
||||||
|
$response = $this->server->dispatch( $request );
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$data = $response->get_data();
|
||||||
|
$names = wp_list_pluck( $data, 'name' );
|
||||||
|
sort( $names );
|
||||||
|
$this->assertEquals( array( 'Burrito', 'Enchilada', 'Taco' ), $names );
|
||||||
|
}
|
||||||
|
|
||||||
public function test_get_terms_private_taxonomy() {
|
public function test_get_terms_private_taxonomy() {
|
||||||
register_taxonomy( 'robin', 'post', array( 'public' => false ) );
|
register_taxonomy( 'robin', 'post', array( 'public' => false ) );
|
||||||
$term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) );
|
$term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) );
|
||||||
|
|
|
@ -1990,7 +1990,10 @@ mockedApiResponse.Schema = {
|
||||||
"slug": {
|
"slug": {
|
||||||
"required": false,
|
"required": false,
|
||||||
"description": "Limit result set to terms with a specific slug.",
|
"description": "Limit result set to terms with a specific slug.",
|
||||||
"type": "string"
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -2225,7 +2228,10 @@ mockedApiResponse.Schema = {
|
||||||
"slug": {
|
"slug": {
|
||||||
"required": false,
|
"required": false,
|
||||||
"description": "Limit result set to terms with a specific slug.",
|
"description": "Limit result set to terms with a specific slug.",
|
||||||
"type": "string"
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue