Created
November 22, 2015 05:29
-
-
Save krishna19/4b6ae99a5ee34de25a11 to your computer and use it in GitHub Desktop.
Get attachment ID/Size from url
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
//Return the attachment ID 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; | |
} | |
//Gets an image thumbnail from attachment ID | |
function get_attachment_image_size_from_src( $url, $size = 'large' ){ | |
$image_id = get_attachment_id_from_src( $url ); | |
$image_object = wp_get_attachment_image_src( $image_id, $size ); | |
return $image_object[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment