WordPress always adds an alt
attribute to images added via the Media Library so finding images without alternative text is easy!
What we need to do is:
- Get posts of all Post Types
- Only get Published, Privately Published & Draft posts
- Look for the presence of an
img
tag with an empty value foralt
The SQL
SELECT * FROM `wp_posts` WHERE post_status IN ('publish', 'draft', 'private') AND post_content LIKE '%<img%alt=""%'