Created
October 30, 2013 08:23
-
-
Save jessijean/7228918 to your computer and use it in GitHub Desktop.
Returns attachment Id from it's url src
From http://wordpress.org/support/topic/need-to-get-attachment-id-by-image-url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment