0

I would like to delete all files that end with -1.jpg in media library as they are duplicates.

I use sudo rm -r *-1.jpg at the wp-content/uploads folder. They are deleted successfully. However, images still show up in media library. Are there other areas I need to delete them?

1

If you want to delete files from the Media Library, then you need to delete both the database entry (attachment post) and the actual file (files to be more precise as there might be one or more scaled versions of the same image file depending on your setup).

You can do these both actions for example with wp_delete_attachment(), https://developer.wordpress.org/reference/functions/wp_delete_attachment/, which of course requires you to first know the IDs of the attachment posts, which have -1.jpg on the file name.

To find these IDs you'll need to query the yourprefix_posts database table. You'll need to use $wpdb as you need to query the guid column to find attachment posts with the matching file name as the file path/url is stored in that column - if I remember correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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