Skip to content

Instantly share code, notes, and snippets.

@jkudish
Forked from anonymous/getIDfromGUID.php
Last active September 4, 2015 19:03
Show Gist options
  • Save jkudish/75ccbcf05d3a231f350e to your computer and use it in GitHub Desktop.
Save jkudish/75ccbcf05d3a231f350e to your computer and use it in GitHub Desktop.
<?php
//Locate the attachment post's ID in the database based on the GUID.
function getIDfromGUID( $existing_image ){
global $wpdb;
return $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=attachment AND guid=%s", $existing_image ) );
}
$existing_image = "http://guidevoyage.org.dev/wp-content/uploads/2012/02/Fontaine-de-Trevi.jpg";
var_dump( getIDfromGUID( $existing_image ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment