- Timestamp:
- 12/14/2014 07:00:31 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/meta.php
r30753 r30846 1420 1420 break; 1421 1421 1422 // EXISTS with a value is interpreted as '='. 1423 case 'EXISTS' : 1424 $meta_compare = '='; 1425 $where = $wpdb->prepare( '%s', $meta_value ); 1426 break; 1427 1428 // 'value' is ignored for NOT EXISTS. 1429 case 'NOT EXISTS' : 1430 $where = ''; 1431 break; 1432 1422 1433 default : 1423 1434 $where = $wpdb->prepare( '%s', $meta_value ); -
trunk/tests/phpunit/tests/post/query.php
r29979 r30846 539 539 540 540 /** 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 /** 541 606 * @ticket 18158 542 607 * @group meta
Note: See TracChangeset
for help on using the changeset viewer.