WordPress.org

Make WordPress Core

Opened 15 months ago

Closed 13 months ago

Last modified 4 months ago

#24133 closed defect (bug) (duplicate)

WP_Query, multiple 'orderby' values glitch

Reported by: racura Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5.1
Component: Query Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

According to the documentation, WP_Query argument 'orderby' allows for multiple values, but it doesn't work.

Looking in the code i found out why, the 'order' is only being applied to the last item in the list.

So for instance:

('orderby' => 'title menu_order', 'order' => 'DESC')

Will end up as

"ORDER BY $wpdb->posts.menu_order, $wpdb->posts.post_menu_order DESC"

To fix (I hope), the following needs to be done to query.php line 2387

$orderby_array[] = $orderby.' '.$q['order'];

Change History (5)

comment:1 racura15 months ago

Sorry, the code fix should be:

    $orderby_array[] = $orderby.' '.$q['order'];

And remove lines 2393 and 2394

comment:2 drozdz13 months ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #17065.

comment:3 SergeyBiryukov13 months ago

  • Component changed from General to Query
  • Milestone Awaiting Review deleted

comment:4 ircbot4 months ago

This ticket was mentioned in IRC in #wordpress-dev by SergeyBiryukov. View the logs.

comment:5 SergeyBiryukov4 months ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.