Skip to content

Instantly share code, notes, and snippets.

@kachi
Last active May 21, 2017 23:42
Show Gist options
  • Save kachi/313242fa8b1a1889a33ed81d7e376e62 to your computer and use it in GitHub Desktop.
Save kachi/313242fa8b1a1889a33ed81d7e376e62 to your computer and use it in GitHub Desktop.
<?php
//https://pippinsplugins.com/retrieve-attachment-id-from-image-url/
function pippin_get_image_id($image_url) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment