[wp-trac] [WordPress Trac] #16584: Media Gallery sorts images by two columns despite get_posts not supporting this properly

WordPress Trac wp-trac at lists.automattic.com
Thu Feb 17 22:25:55 UTC 2011


#16584: Media Gallery sorts images by two columns despite get_posts not supporting
this properly
--------------------------+-----------------------------
 Reporter:  smerriman     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  3.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16584>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list