Query all posts where meta value is empty

I think you forgot about the inherit post status. The default one in WP_Query is publish.

You should also use = instead of LIKE, to avoid using LIKE '%%' in the SQL query.

So try to add this:

'post_status' => 'inherit'

and

'compare' => '='

into your query arguments, to match the empty _wp_attachment_image_alt string values.

Leave a Comment