There is no post_title
in WP_Query
‘s parameter list. You need to use name
, which accepts a slug not the actual post title.
name (string) – use post slug.
It looks like all you are doing is getting an ID. That is a very heavy query if that is all you need. You can alter the parameters to lighten this up.
$query_args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => 1, // since you seem to be using only the first result
'ignore_sticky_posts' => true, // don't juggle sticky posts to the top
'no_found_rows' => true, // don't calculate total returns
'name' => $image_name,
'fields' => 'ids' // only return the post IDs
);