| | 541 | * @ticket 30681 |
| | 542 | */ |
| | 543 | public function test_meta_query_compare_exists() { |
| | 544 | $posts = $this->factory->post->create_many( 3 ); |
| | 545 | add_post_meta( $posts[0], 'foo', 'bar' ); |
| | 546 | add_post_meta( $posts[2], 'foo', 'baz' ); |
| | 547 | |
| | 548 | $query = new WP_Query( array( |
| | 549 | 'fields' => 'ids', |
| | 550 | 'meta_query' => array( |
| | 551 | array( |
| | 552 | 'compare' => 'EXISTS', |
| | 553 | 'key' => 'foo', |
| | 554 | ), |
| | 555 | ), |
| | 556 | ) ); |
| | 557 | |
| | 558 | $this->assertEqualSets( array( $posts[0], $posts[2] ), $query->posts ); |
| | 559 | } |
| | 560 | |
| | 561 | /** |
| | 562 | * @ticket 30681 |
| | 563 | */ |
| | 564 | public function test_meta_query_compare_exists_with_value_should_convert_to_equals() { |
| | 565 | $posts = $this->factory->post->create_many( 3 ); |
| | 566 | add_post_meta( $posts[0], 'foo', 'bar' ); |
| | 567 | add_post_meta( $posts[2], 'foo', 'baz' ); |
| | 568 | |
| | 569 | $query = new WP_Query( array( |
| | 570 | 'fields' => 'ids', |
| | 571 | 'meta_query' => array( |
| | 572 | array( |
| | 573 | 'compare' => 'EXISTS', |
| | 574 | 'value' => 'baz', |
| | 575 | 'key' => 'foo', |
| | 576 | ), |
| | 577 | ), |
| | 578 | ) ); |
| | 579 | |
| | 580 | $this->assertEqualSets( array( $posts[2] ), $query->posts ); |
| | 581 | } |
| | 582 | |
| | 583 | /** |
| | 584 | * @ticket 30681 |
| | 585 | */ |
| | 586 | public function test_meta_query_compare_not_exists_should_ignore_value() { |
| | 587 | $posts = $this->factory->post->create_many( 3 ); |
| | 588 | add_post_meta( $posts[0], 'foo', 'bar' ); |
| | 589 | add_post_meta( $posts[2], 'foo', 'baz' ); |
| | 590 | |
| | 591 | $query = new WP_Query( array( |
| | 592 | 'fields' => 'ids', |
| | 593 | 'meta_query' => array( |
| | 594 | array( |
| | 595 | 'compare' => 'NOT EXISTS', |
| | 596 | 'value' => 'bar', |
| | 597 | 'key' => 'foo', |
| | 598 | ), |
| | 599 | ), |
| | 600 | ) ); |
| | 601 | |
| | 602 | $this->assertEqualSets( array( $posts[1] ), $query->posts ); |
| | 603 | } |
| | 604 | |
| | 605 | /** |