When you delete your posts, attachments from it don’t get deleted automatically. They keep staying in the WordPress Media Library and on your web server eating disk space and messing the things up.
Delete unattached attachments (orphaned media that is not attached to any WordPress post, page or custom post)
This function will delete them permanently from Media Library and from wp-content/uploads folder too.
Just mind what your are doing.
On the one of the projects we added images and descriptions on tags archive pages for SEO purposes and these images as you understand are not attached to any post, however that doesn’t mean we want to get rid of them.
If you’ve thoroughly thought this out and you are sure you want to get rid of this orphaned media, make backup and just do it 😉
Delete custom post type attachments
This function is useful when you need to delete all images that are attached to specified CPT. Mind to change “card” to your custom post type name.
You’ve made a backup, have not you?)