if ( isset( $posts ) && isset( $posts[0]->{$id_field} ) ) {
                // Attachment does exist after checking the matching value. we want its id.
                $attachment_id = $posts[0]->{$id_field};

                if ( true === $check_only ) {