| | 437 | * @ticket 39140 |
| | 438 | */ |
| | 439 | public function test_tax_query_single_query_multiple_hierarchical_terms_operator_and() { |
| | 440 | $europe = self::factory()->term->create( |
| | 441 | array( |
| | 442 | 'taxonomy' => 'category', |
| | 443 | 'name' => 'Europe', |
| | 444 | ) |
| | 445 | ); |
| | 446 | $spain = self::factory()->term->create( |
| | 447 | array( |
| | 448 | 'taxonomy' => 'category', |
| | 449 | 'name' => 'Spain', |
| | 450 | 'parent' => $europe, |
| | 451 | ) |
| | 452 | ); |
| | 453 | $south_america = self::factory()->term->create( |
| | 454 | array( |
| | 455 | 'taxonomy' => 'category', |
| | 456 | 'name' => 'South America', |
| | 457 | ) |
| | 458 | ); |
| | 459 | $argentina = self::factory()->term->create( |
| | 460 | array( |
| | 461 | 'taxonomy' => 'category', |
| | 462 | 'name' => 'Argentina', |
| | 463 | 'parent' => $south_america, |
| | 464 | ) |
| | 465 | ); |
| | 466 | $post_a = self::factory()->post->create( array( 'post_category' => array( $argentina ) ) ); |
| | 467 | $post_b = self::factory()->post->create( array( 'post_category' => array( $spain ) ) ); |
| | 468 | $post_c = self::factory()->post->create( array( 'post_category' => array( $argentina, $spain ) ) ); |
| | 469 | |
| | 470 | $posts = get_posts( |
| | 471 | array( |
| | 472 | 'fields' => 'ids', |
| | 473 | 'update_post_meta_cache' => false, |
| | 474 | 'update_post_term_cache' => false, |
| | 475 | 'tax_query' => array( |
| | 476 | array( |
| | 477 | 'taxonomy' => 'category', |
| | 478 | 'field' => 'id', |
| | 479 | 'terms' => array( $argentina, $spain ), |
| | 480 | 'operator' => 'AND' |
| | 481 | ), |
| | 482 | ), |
| | 483 | ) |
| | 484 | ); |
| | 485 | |
| | 486 | $this->assertEquals( 1, count( $posts ) ); |
| | 487 | |
| | 488 | $posts = get_posts( |
| | 489 | array( |
| | 490 | 'fields' => 'ids', |
| | 491 | 'update_post_meta_cache' => false, |
| | 492 | 'update_post_term_cache' => false, |
| | 493 | 'tax_query' => array( |
| | 494 | array( |
| | 495 | 'taxonomy' => 'category', |
| | 496 | 'field' => 'id', |
| | 497 | 'terms' => array( $europe, $south_america ), |
| | 498 | 'operator' => 'AND' |
| | 499 | ), |
| | 500 | ), |
| | 501 | ) |
| | 502 | ); |
| | 503 | |
| | 504 | $this->assertEquals( 1, count( $posts ) ); |
| | 505 | |
| | 506 | } |
| | 507 | |
| | 508 | /** |