[wp-trac] [WordPress Trac] #18158: Meta Query for posts with a meta key not set (IS NULL).

WordPress Trac wp-trac at lists.automattic.com
Fri Jan 13 13:01:10 UTC 2012


#18158: Meta Query for posts with a meta key not set (IS NULL).
-------------------------------------------------+-------------------------
 Reporter:  johnnyb                              |       Owner:
     Type:  enhancement                          |  georgestephanis
 Priority:  normal                               |      Status:  accepted
Component:  Query                                |   Milestone:  Future
 Severity:  normal                               |  Release
 Keywords:  dev-feedback needs-testing has-      |     Version:  3.2.1
  patch                                          |  Resolution:
-------------------------------------------------+-------------------------

Comment (by georgestephanis):

 Oh drat, I left it as INNER JOIN, didn't I?  I meant for that to be LEFT
 JOIN.  My bad.

 Basically, if it can't find anything to join to, it will just return
 'NULL' for those values.  So if you test for NULL in a field that would
 never be null if a value is returned (like post_id for instance, like I
 have) -- it will tell you if it found something to join with, or came up
 empty.

 The only thing I haven't considered if what if there's multiple instances
 of a meta_key -- if that would return multiple rows in the final result.
 I wrote it assuming a max of 1 per.  I'll need to test for that.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18158#comment:15>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list