WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] delete 100,000 images from media library (8 posts)

  1. eduguytoo
    Member
    Posted 2 years ago #

    I have a odd issue in a wordpress installation where there appears to be over 100,000 images, in the media library, I am trying to find out how I can locate these files on the server, and delete them all.

    PHP has a time out issue, so using mass delete, returns an error so thats not a good method, deleting 300 images at a time is not a good option imagine how long that would take.

    I have deleted all the images in the uploads folder, however apparently the database still holds references to these files, can someone point me to a method of using PHP admin to delete the references to these images.

    Any suggestions would be welcomed.

  2. chrismccorkle
    Member
    Posted 2 years ago #

    Keep in mind that deleting files from the server via SSH, FTP, etc. will not remove the entries for them in the WordPress media library.

    Do this if you want to clear the entire media library on the the server and in WordPress (remember to back everything up first):

    Browse to the uploads folder, then do rm -rf *. Wait until all is clear and the uploads folder is empty.

    I'll edit this shortly with the database solution.

  3. eduguytoo
    Member
    Posted 2 years ago #

    yes, I see that it is still showing references in the database, thanks for the information, I appreciate that. I looked at some of the tables but I could not identify for sure which ones hold the reference data.

  4. chrismccorkle
    Member
    Posted 2 years ago #

    You may be able to run a quick command in phpMyAdmin that removes all entries containing a post_type of "attachment".

  5. chrismccorkle
    Member
    Posted 2 years ago #

    Locate your WordPress database in phpMyAdmin, then run this SQL command to delete ALL attachments:

    DELETE FROM `wp_posts` WHERE `post_type` = "attachment"

    As always, use with caution. This coupled with the SSH command should get you fixed up.

  6. eduguytoo
    Member
    Posted 2 years ago #

    Thanks, yes, that worked saved me a ton of time.

  7. Simon
    Member
    Posted 1 year ago #

    For anyone else reading this - be aware that depending on plugins used, you will have at least one, maybe 4 or more records on the wp_postmeta table. It is wise to delete these two, as if you don't they end up being orphaned in the database, and taking up space / slowing things down.

    So, first:

    DELETE FROM wp_postmeta
    WHERE post_id IN
    (
    SELECT id
    FROM wp_posts
    WHERE post_type = 'attachment'
    )
    ;

    Then once executed,

    DELETE FROM wp_posts WHERE post_type = 'attachment'

    I just deleted 8,400 images, after deleting 25,000+ rows in wp_postmeta - if you don't do this and your site is or will possibly be big in the future, you may run into performance issues...

    Thanks
    Si

  8. gerygreen
    Member
    Posted 1 year ago #

    I would like to recommend the plugin WP Media Cleaner.
    It helps me testing on local server big sites with hundred of thousands of pictures. It handles retina and woocommerce products as well.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.