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 (66)
- Keywords needs-patch added; dev-feedback removed
- Milestone changed from Awaiting Review to Future Release
comment:9 thomas.mery — 2 years ago
- 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).
comment:11 georgestephanis — 2 years ago
- Keywords has-patch added
- Owner set to georgestephanis
- Status changed from new to accepted
comment:16 follow-up: ↓ 17 georgestephanis — 2 years ago
comment:19 scribu — 23 months ago
- Keywords dev-feedback removed
- Milestone changed from Future Release to 3.4
comment:40 follow-up: ↓ 42 scribu — 18 months ago
- Keywords early removed
- Milestone changed from Future Release to 3.5