| | 430 | |
| | 431 | /** |
| | 432 | * @ticket 41796 |
| | 433 | */ |
| | 434 | public function test_number_should_work_with_object_ids() { |
| | 435 | register_taxonomy( 'wptests_tax', 'post' ); |
| | 436 | |
| | 437 | $term_1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); |
| | 438 | $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); |
| | 439 | |
| | 440 | $post_1 = self::factory()->post->create(); |
| | 441 | $post_2 = self::factory()->post->create(); |
| | 442 | |
| | 443 | wp_set_object_terms( $post_1, array( $term_1, $term_2 ), 'wptests_tax' ); |
| | 444 | wp_set_object_terms( $post_2, array( $term_1 ), 'wptests_tax' ); |
| | 445 | |
| | 446 | $q = new WP_Term_Query( array( |
| | 447 | 'taxonomy' => 'wptests_tax', |
| | 448 | 'object_ids' => array( $post_1, $post_2 ), |
| | 449 | 'number' => 2, |
| | 450 | ) ); |
| | 451 | |
| | 452 | $this->assertEqualSets( array( $term_1, $term_2 ), wp_list_pluck( $q->terms, 'term_id' ) ); |
| | 453 | } |
| | 454 | |
| | 455 | /** |
| | 456 | * @ticket 41796 |
| | 457 | */ |
| | 458 | public function test_number_should_work_with_object_ids_and_all_with_object_id() { |
| | 459 | register_taxonomy( 'wptests_tax', 'post' ); |
| | 460 | |
| | 461 | $term_1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); |
| | 462 | $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); |
| | 463 | |
| | 464 | $post_1 = self::factory()->post->create(); |
| | 465 | $post_2 = self::factory()->post->create(); |
| | 466 | |
| | 467 | wp_set_object_terms( $post_1, array( $term_1, $term_2 ), 'wptests_tax' ); |
| | 468 | wp_set_object_terms( $post_2, array( $term_1 ), 'wptests_tax' ); |
| | 469 | |
| | 470 | $q = new WP_Term_Query( array( |
| | 471 | 'taxonomy' => 'wptests_tax', |
| | 472 | 'object_ids' => array( $post_1, $post_2 ), |
| | 473 | 'fields' => 'all_with_object_id', |
| | 474 | 'number' => 2, |
| | 475 | ) ); |
| | 476 | |
| | 477 | $this->assertEqualSets( array( $term_1, $term_1 ), wp_list_pluck( $q->terms, 'term_id' ) ); |
| | 478 | } |