Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#12755 closed enhancement (fixed)

Detached media sorted in reverse by date

Reported by: sbressler's profile sbressler Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.0
Component: Media Keywords: needs-refresh commit
Focuses: Cc:


Media that's unattached to any post (i.e. at this page: "/wp-admin/upload.php?detached=1" for a WP install) seems to be sorted by post_date ascending (starting with the oldest media) rather than descending. I was able to replicate this in WP 2.9.1, WP 2.9.2 MU and WP 3.0.

I couldn't quite find the correct line to fix, but line 305 of media.php does correct sorting:

$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";

So it must be somewhere else since that query doesn't run if loading detached media.

Attachments (1)

12755.patch (1.3 KB) - added by sbressler 14 years ago.
My first stab at a patch

Download all attachments as: .zip

Change History (10)

#1 @nacin
14 years ago

Depending on the situation, it's one of these queries:

// when searching for orphaned attachments (had a parent).
$orphans = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN (%s) LIMIT %d, %d", $lost, $start, $media_per_page ) );
// when searching for attachments without a parent (and never had one).
$orphans = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT %d, %d", $start, $media_per_page ) );

14 years ago

My first stab at a patch

#2 @sbressler
14 years ago

Is there something else that should be done before this is considered "commitable" to core?

#3 @nacin
14 years ago

  • Component changed from Administration to Media
  • Keywords has-patch added; media ordering sorting removed
  • Milestone changed from Unassigned to 3.1
  • Type changed from defect (bug) to enhancement

Assuming it works and doesn't break anything, consider it good for 3.1.

#4 @sbressler
14 years ago

Just to report my testing, it worked excellently for me and didn't break anything. I only barely know how the automated tests are integrated in WP, but I don't think this needs one. Unattached media were properly sorted when I applied my patch above.

#5 @nacin
14 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Triage to 3.1

Looks good.

#6 @nacin
14 years ago

  • Keywords needs-refresh added; has-patch removed

Patch no longer applies.

#7 @RyanMurphy
14 years ago

Items sort descending for me. It might have been fixed in scribu's table work.

#8 @sbressler
14 years ago

Yep, just confirmed that this works now in 3.1 with scribu's work!

#9 @sbressler
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.