Created
May 18, 2017 13:10
-
-
Save lomboboo/609adc15b217ce19c75638d440d54308 to your computer and use it in GitHub Desktop.
Get attachment ID by attachment 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
get_attachment_id( $att_url ) { | |
global $wpdb; | |
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE guid='%s';", $att_url ) ); | |
return $attachment[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment