WordPress – delete all media files

To delete the media files without leaving traces in the database, do the following:

  1. Connect to the mysql database – using phpmyadmin, for example – and run the following queries:
    DELETE FROM wp_postmeta WHERE post_id IN ( SELECT id FROM wp_posts WHERE post_type = ‘attachment’ ) ; DELETE FROM wp_posts WHERE post_type = ‘attachment’;
  2. Delete the files and folders stored in ./wp-content/uploads/