Meta Query for posts with a meta key not set (IS NULL).
|Reported by:||johnnyb||Owned by:||georgestephanis|
|Component:||Query||Keywords:||has-patch needs-unit-tests commit|
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
4 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).
- Keywords has-patch added
- Owner set to georgestephanis
- Status changed from new to accepted
4 years ago
- Keywords early removed
- Milestone changed from Future Release to 3.5