Changeset 59458
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r58706 r59458 228 228 * 229 229 * @since 4.7.0 230 * @since 6.8.0 Respect default query arguments set for the taxonomy upon registration. 230 231 * 231 232 * @param WP_REST_Request $request Full details about the request. … … 294 295 } 295 296 } 297 } 298 299 /* 300 * When a taxonomy is registered with an 'args' array, 301 * those params override the `$args` passed to this function. 302 * 303 * We only need to do this if no `post` argument is provided. 304 * Otherwise, terms will be fetched using `wp_get_object_terms()`, 305 * which respects the default query arguments set for the taxonomy. 306 */ 307 if ( 308 empty( $prepared_args['post'] ) && 309 isset( $taxonomy_obj->args ) && 310 is_array( $taxonomy_obj->args ) 311 ) { 312 $prepared_args = array_merge( $prepared_args, $taxonomy_obj->args ); 296 313 } 297 314 -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r56746 r59458 481 481 $this->assertCount( 2, $data ); 482 482 $this->assertSame( 'Cape', $data[0]['name'] ); 483 } 484 485 /** 486 * @ticket 62500 487 */ 488 public function test_get_items_custom_tax_without_post_arg_respects_tax_query_args() { 489 register_taxonomy( 490 'batman', 491 'post', 492 array( 493 'show_in_rest' => true, 494 'sort' => true, 495 'args' => array( 496 'order' => 'DESC', 497 'orderby' => 'name', 498 ), 499 ) 500 ); 501 $controller = new WP_REST_Terms_Controller( 'batman' ); 502 $controller->register_routes(); 503 $term1 = self::factory()->term->create( 504 array( 505 'name' => 'Cycle', 506 'taxonomy' => 'batman', 507 ) 508 ); 509 $term2 = self::factory()->term->create( 510 array( 511 'name' => 'Pod', 512 'taxonomy' => 'batman', 513 ) 514 ); 515 $term3 = self::factory()->term->create( 516 array( 517 'name' => 'Cave', 518 'taxonomy' => 'batman', 519 ) 520 ); 521 522 $request = new WP_REST_Request( 'GET', '/wp/v2/batman' ); 523 $response = rest_get_server()->dispatch( $request ); 524 $this->assertSame( 200, $response->get_status() ); 525 526 $data = $response->get_data(); 527 $this->assertCount( 3, $data ); 528 $this->assertSame( 529 array( 'Pod', 'Cycle', 'Cave' ), 530 array_column( $data, 'name' ) 531 ); 483 532 } 484 533
Note: See TracChangeset
for help on using the changeset viewer.