Meta Query for posts with a meta key not set (IS NULL).
|Reported by:||johnnyb||Owned by:||georgestephanis|
|Severity:||normal||Keywords:||has-patch needs-unit-tests commit|
|Cc:||marko@…, scott@…, wycks, micahwave, chappellind@…, dromsey@…, coenjacobs@…, aaroncampbell, dancameron, batmoo@…, ehitter@…, bananastalktome@…, j.yzbek@…, timersys, xoodrew@…|
In the meta_query, we should be able to query for posts that don't have a certain meta key at all. I suggest a syntax something like this:
... meta_query => array( array( 'key' => '_my_special_meta', 'compare' => 'NOT EXISTS' ) ) ...
Alternately this could be handled invisibly along the lines of:
... meta_query => array( array( 'key' => '_my_special_meta', 'value' => 'a_value_this_might_have', 'compare' => '!=' ) ) ...
This could be done using a left join, and not some sort of special case like above. Since it's a left join we may have to be careful that we don't end up with a bunch of junk rows in the query, however.
Change History (64)
- Keywords needs-patch added; dev-feedback removed
- Milestone changed from Awaiting Review to Future Release
- Summary changed from Meta Query for posts with a meta key not set. to Meta Query for posts with a meta key not set (IS NULL).
- Keywords has-patch added
- Owner set to georgestephanis
- Status changed from new to accepted
- Keywords dev-feedback removed
- Milestone changed from Future Release to 3.4
- Keywords early removed
- Milestone changed from Future Release to 3.5