Delete unused images in WordPress using WP CLI
This small script uses a for loop to delete one post ID at a time, it will go through the database and list all media files uploaded in the provided data range that are not used inside posts. Change the date range according to your needs.