[wp-trac] [WordPress Trac] #42031: Orderby with multiple meta keys not ordering correctly

WordPress Trac noreply at wordpress.org
Fri Sep 29 10:13:13 UTC 2017


#42031: Orderby with multiple meta keys not ordering correctly
--------------------------+-----------------------------
 Reporter:  gekomees      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  4.8.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I have a meta field in the database as an array. Looks something like
 this:
 a:2:{i:0;s:4:"sold";i:1;s:12:"constructing";}
 An array containing any amount of four possible values.

 Basically, the meta_query I have is this:
 {{{#!php
 <?php
 'meta_query' => array(
         'relation' => 'OR',
         'on_sale' => array(
                 'key' => 'acf_project_status',
                 'value' => 'on_sale',
                 'compare' => 'LIKE'
          ),
         'constructing' => array(
                 'key' => 'acf_project_status',
                 'value' => 'constructing',
                 'compare' => 'LIKE'
          ),
         'ready' => array(
                 'key' => 'acf_project_status',
                 'value' => 'ready',
                 'compare' => 'LIKE'
          ),
         'sold' => array(
                 'key' => 'acf_project_status',
                 'value' => 'sold',
                 'compare' => 'LIKE'
          )
 ),
 }}}


 And the orderby:
 {{{#!php
 <?php
 'orderby' => array(
         'on_sale' => 'DESC',
         'constructing' => 'DESC',
         'ready' => 'DESC',
         'sold' => 'DESC',
 )
 }}}


 What I expect to happen is the posts ordered as such:
 1) posts, that have on_sale
 2) posts, that have constructing
 3) posts, that have ready
 4) posts, that have sold

 Posts that have on_sale indeed are first, but after that no more sorting
 is applied. The rest of the results come out as is.
 For example I had 2 on_sale show up first but a post having "constructing"
 was dead last after readies and solds.

 I don't think the problem is in searching from array with LIKE since by
 themselves WP_Query can manage all the meta_queries successfully.
 I have also tried the following format for orderby:
 {{{#!php
 <?php
 'orderby' => 'on_sale constructing ready sold'
 }}}
 Of course, this didn't change anything.

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


More information about the wp-trac mailing list