Opened 12 years ago
Closed 11 years ago
#22967 closed defect (bug) (fixed)
Null value in meta query changes the type of comparison
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.8 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Query | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
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 '='.
For example:
$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.
Attachments (2)
Change History (9)
Note: See
TracTickets for help on using
tickets.
Related: [22103] (for #19729).