[wp-trac] [WordPress Trac] #58200: Empty result when meta_query is supposed to select date less than certain date

WordPress Trac noreply at wordpress.org
Fri Nov 10 09:04:06 UTC 2023


#58200: Empty result when meta_query is supposed to select date less than certain
date
--------------------------+------------------------------
 Reporter:  oglekler      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by domainsupport):

 This sounds like something we have noticed that has changed in v6.4.

 Prior to v6.4 an empty `expiry_date` meta value would not have been
 included in the results of the following `meta_query` ...

 {{{#!php
 <?php
 'meta_query' => array(
         array(
                 'key' => 'expiry_date',
                 'compare' => '<',
                 'value' => date('Y-m-d H:i:s'),
                 'type' => 'DATETIME'
         )
 )
 }}}

 ... but now you need to use the following `meta_query` so as not to
 include empty meta in the results (we've also added the `EXISTS` condition
 for "belt and braces" ...

 {{{#!php
 <?php
 'meta_query' => array(
         array(
                 'key' => 'expiry_date',
                 'compare' => 'EXISTS'
         ),
         array(
                 'key' => 'expiry_date',
                 'value'   => array(''),
                 'compare' => 'NOT IN'
         ),
         array(
                 'key' => 'expiry_date',
                 'compare' => '<',
                 'value' => date('Y-m-d H:i:s'),
                 'type' => 'DATETIME'
         )
 )
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58200#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list