Finding the attachment_id even after site migration breaks the link between url and guid

Alteration to find the attachment/post ID from the postmeta table rather than the guid held in posts table.

This (hopefully!) fixes the problem where the url differs from the guid because of site migrations i.e. where images are loaded onto one site (at which point the guid and the url are the same) but then the site is migrated and the url changes but the guid doesn't.