How to get an attachment id from a filename
I have not been able to find a reliable solution for how to lookup the id for attachments in the media library from a filename as Wordpress does not appear to provide such a function.
Most solutions rely on searching the GUID field in various tables, however there are issues with attachments uploaded with greater than 2560px resolution. Wordpress appends '-scaled' to the filename returned by functions like get_attached_file(), but this is not reflected in the guid database column.
I'd be grateful for a generic function that returns the attachment id when given a filename.
Topic functions attachments Wordpress
Category Web