Opened 14 years ago
Closed 11 years ago
#16584 closed defect (bug) (worksforme)
Media Gallery sorts images by two columns despite get_posts not supporting this properly
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.6 |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description
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.
We finally ditched this UI in 3.5.