Support » Plugins » Hacks » Attachment IDs for Attachments that Have been scaled up in the editor

  • I found a little script in one of the forms here (topic is closed) that works great for find an attachment id from the source of an image.


    function get_attachment_id_from_src ($image_src) {
    global $wpdb;
    $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
    $id = $wpdb->get_var($query);
    return $id;
    }

    This all works great with cropping and scaling images down – just regenerate the thumbnails and everything is fine. But, if I scale the image UP it doesn’t work anymore. I’m using Advanced Custom Fields for meta boxes on my post types, but that part of things seems to be working. The SELECT statement in the code above is what seems to be failing – even though I can see an attachment ID in the media library. And furthermore the attachment ID works if I just insert it into my theme manually. Any insight is appreciated!

  • The topic ‘Attachment IDs for Attachments that Have been scaled up in the editor’ is closed to new replies.