Respect the compare operator value in meta_query when value evaluates to null. Adds Unit Test.

Props bradyvercher, gradyetc.
Fixes #22967.



git-svn-id: https://develop.svn.wordpress.org/trunk@26053 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2013-11-08 22:51:03 +00:00
parent 0670cf7cc4
commit cc19bb3a57
2 changed files with 18 additions and 1 deletions

View File

@@ -105,4 +105,18 @@ class Tests_Meta_Query extends WP_UnitTestCase {
$this->assertEquals( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_key = 'my_third_key'" ) );
}
/**
* @ticket 22967
*/
function test_null_value_sql() {
global $wpdb;
$query = new WP_Meta_Query( array(
array( 'key' => 'abc', 'value' => null, 'compare' => '=' )
) );
$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
$this->assertEquals( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = '')" ) );
}
}