Is there a function in WordPress to check if image from the media library is attached to any post?

So I’d like to find out what images from the Media library are not attached to anything so I can delete them, although I googled I did not found anything or my request wasn’t accurate enough, I am not sure. Do you know any of ways to how to detect that? I also want to try to write an SQL statement, however I am not sure if I should look for relationships in postmeta table, because technically the image uploaded trough a media library as I know is considered as a post, so maybe I can find a way somehow. Although I haven’t tried anything like that yet.

Any help is really appreciated


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Your Advertisement Here