Skip to content

Instantly share code, notes, and snippets.

@valeriu
Created May 16, 2015 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valeriu/0f42ed0a82a29ac52496 to your computer and use it in GitHub Desktop.
Save valeriu/0f42ed0a82a29ac52496 to your computer and use it in GitHub Desktop.
/*------------------------------------------------------------
* Get Attachment ID from image src
* Author: http://stylishwp.com/
============================================================*/
if ( ! function_exists( 'swp_get_attachment_id_from_src' ) ) :
function swp_get_attachment_id_from_src ( $image_src ) {
global $wpdb;
$id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid = %s", $image_src) );
return $id;
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment