Null value in meta query changes the type of comparison
|Reported by:||bradyvercher||Owned by:||wonderboymusic|
If a null value is set in a meta query, it effectively returns the same results as setting the 'compare' arg to 'EXISTS', even if it's explicitly set to the default '='.
$value_var = null; ... meta_query => array( array( 'key' => '_my_meta_key', 'value' => $value_var, 'compare' => '=' ) ) ...
That returns all rows where '_my_meta_key' exists and ignores 'value' instead of treating it like an empty string. This can be troublesome where the value is passed in dynamically like the example, so validation would have to be done prior to every meta query to ensure the value isn't null.
I've attached a patch for review that checks for the existence of the 'value' key rather than using isset and casts it to a string if it's null.