I have a plugin that takes an user selected image from the media library, puts some special effects on it, and then saves a copy of the "enhanced" image back to the library using media_handle_upload().

This works fine, but it puts the updated image at the top of the media library, separating it from the original.

I want to keep the enhanced attachment next to the original, and I learned from this question that data for post attachments is mainly stored in the wp_posts table.

However I can't find what column in the wp_posts is used to sort attachments when the wordpress media library displays them.

Any help with this problem would be much appreciated, thank you!

1 Answer 1


Attachments in Media Library are obtained using WP_Query, so you can modify that query with pre_get_posts action.

By default they are sorted DESC by post_date.

So the easiest way to fix your code would be to change so the new modified attachment has the same post_date set as the original one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.