Make WordPress Core

Opened 11 years ago

Closed 8 years ago

#16584 closed defect (bug) (worksforme)

Media Gallery sorts images by two columns despite get_posts not supporting this properly

Reported by: smerriman Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.6
Component: Media Keywords:
Focuses: Cc:


In the get_media_items function in wp-admin/includes/media.php, attachments are sorted first by menu order, then by post ID by the following line:

$attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );

However, the get_posts in wp-admin/includes/query.php function does not properly support this. It splits up orderby by spaces, and then throws out 'ASC,' as it does not match a valid value. Due to a lucky coincidence, it turns into ORDER BY menu_order, ID DESC which still works in the same way.

I often want to display the first x uploaded images to a post, but allow changing which images are considered the first x via menu_order. If I solely order by ID ASC, that won't work. If I solely order by menu_order ASC, that won't work either, since the ones at the top of the list (latest uploaded) become first in the menu order. The only way to get it to work is to sort by menu_order DESC, ID ASC - but using

{{'orderby' => 'menu_order DESC, ID', 'order' => 'ASC'}}

doesn't not work since the 'DESC,' gets ignored.

There are two possible interpretations of this bug:

a) Remove 'ASC,' in the line I mentioned since it's not valid according to the current rules for get_posts

b) Make get_posts properly support the above method by not having it throw out the extra order condition.

Change History (2)

#1 @nacin
11 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 3.1 to 2.6

#2 @nacin
8 years ago

  • Component changed from General to Media
  • Milestone Future Release deleted
  • Resolution set to worksforme
  • Status changed from new to closed

We finally ditched this UI in 3.5.

Note: See TracTickets for help on using tickets.