Created
August 27, 2012 14:55
-
-
Save SubZane/3489225 to your computer and use it in GitHub Desktop.
WordPress: get_attachment_id_from_src
This file contains 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 ($src) { | |
global $wpdb; | |
$reg = "/-[0-9]+x[0-9]+?.(jpg|jpeg|png|gif)$/i"; | |
$src1 = preg_replace($reg,'',$src); | |
if($src1 != $src){ | |
$ext = pathinfo($src, PATHINFO_EXTENSION); | |
$src = $src1 . '.' .$ext; | |
} | |
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$src'"; | |
$id = $wpdb->get_var($query); | |
return $id; | |
} | |
$image_thumbnail_url = wp_get_attachment_image_src( get_attachment_id_from_src ($image_src), $thumbnail_name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment