[wp-trac] [WordPress Trac] #50081: orderby datetime field

WordPress Trac noreply at wordpress.org
Mon May 4 16:54:41 UTC 2020


#50081: orderby datetime field
--------------------------+-----------------------------
 Reporter:  saltnpixels   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I was creating an event post type and wanted to order a query by event
 date, a custom field.

 I was having trouble because the documentation says I can use an orderby
 => 'meta_value_datetime'.
 This did not work.

 {{{#!php
 <?php
 array(
                 'post_type'      => 'event',
                 'posts_per_page' => - 1,
                 'order' => 'ASC',
                 'meta_key' => 'due_date', //the custom field saved as
 Y-m-d H:i:s.
                 'orderby' => 'meta_value_datetime',
                 'meta_type' => 'DATETIME',
 )
 }}}

 Is this a bug? After much playing around by adding and removing the
 meta_type, trying all different things I got it working simply by using
 meta_value

 {{{#!php
 <?php
 array(
                 'post_type'      => 'event',
                 'posts_per_page' => - 1,
                 'order' => 'ASC',
                 'meta_key' => 'due_date', //the custom field saved as
 Y-m-d H:i:s.
                 'orderby' => 'meta_value',
                 'meta_type' => 'DATETIME',
 )
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50081>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list