How do we get posts where the meta key does not exist in a post.
I have created a meta_key video. and i want to be able to get some posts with WP_Query where custom field video does not exist or is blank.
$fsquery = new WP_Query(
array (
'posts_per_page' => 1,
'featured' => 'yes',
'meta_key'=>'video',
'meta_value'=>''
)
);
this is not working.
There’s actually a better solution that will (hopefully) be rolling out in WordPress 3.4 — you can run the patch as a hotfix now if you’d like, but here’s the TRAC link for the patch:
http://core.trac.wordpress.org/ticket/18158
With this, you can do …
or, swap it out for ‘compare’ => ‘EXISTS’ instead if you like.
-George
You can use
posts_where
filter hook and create a Subquery to exclude all posts with the meta_key of video:used only in WP 3.5. It’s still a beta version at the moment.