Created
May 23, 2016 07:42
-
-
Save ville6000/0c472fd200e95ca94065889957b4fec5 to your computer and use it in GitHub Desktop.
Get Attachment ID from 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
<?php | |
function get_attachment_id_from_url( $image_url ) { | |
global $wpdb; | |
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ) ); | |
return $attachment[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment