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

WordPress Trac noreply at wordpress.org
Thu Jan 24 18:34:15 UTC 2013


#18158: Meta Query for posts with a meta key not set (IS NULL).
-----------------------------------------------+---------------------------
 Reporter:  johnnyb                            |       Owner:
     Type:  enhancement                        |  georgestephanis
 Priority:  normal                             |      Status:  closed
Component:  Query                              |   Milestone:  3.5
 Severity:  normal                             |     Version:  3.2.1
 Keywords:  has-patch needs-unit-tests commit  |  Resolution:  fixed
-----------------------------------------------+---------------------------

Comment (by timersys):

 This query should work or not?

 {{{
         $the_query = new WP_Query(
                 array(
                         'post_type' => 'post',
                         'category__in'    => array(1,2) ,
                         'posts_per_page' => -1,
                         'meta_query'    => array(
                                 relation' => 'OR',

                                 array( // posts with not key at all
                                 'key' => 'my_custom_key',
                                 'compare' => 'NOT EXISTS'
                                  ),
                                 array( //or posts with key set to false
                                 'key'   => 'my_custom_key',
                                 'value' => '0',
                                 'compare' => '='
                                 )
                         )
                 )
         );
 }}}

 If i make the meta_query with one condition it works in both cases.
 As soon as i add both conditions and 'OR' relation it wont work at all.

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


More information about the wp-trac mailing list