WordPress How do I delete thousands of unattached images?

That’s a lot of unattached images. If you have couple of hundred images then you can delete them manually from media library.

1. Click 'Screen Options' at the top right and set 'Show on screen' to 200.
2. Click 'Apply'.
3. Click the checkbox just under 'Bulk Actions' to check all images on the page.
4. Select 'Delete Permanently' in the 'Bulk Actions' dropdown.
5. Click 'Apply'.

WordPress SQL query to delete all media and attachments

# First:
DELETE FROM wp_postmeta
WHERE post_id IN
FROM wp_posts
WHERE post_type = 'attachment'
# Second:
DELETE FROM wp_posts WHERE post_type = 'attachment';