Skip to content

Instantly share code, notes, and snippets.

@lomboboo
Created May 18, 2017 13:10
Show Gist options
  • Save lomboboo/609adc15b217ce19c75638d440d54308 to your computer and use it in GitHub Desktop.
Save lomboboo/609adc15b217ce19c75638d440d54308 to your computer and use it in GitHub Desktop.
Get attachment ID by attachment URL
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