Skip to content

Instantly share code, notes, and snippets.

View stefb69's full-sized avatar

Stéphane Benoit stefb69

View GitHub Profile
@stefb69
stefb69 / Asset.php
Last active August 29, 2015 14:23 — forked from SubZane/Asset.php
function get_attachment_id_from_src ($src) {
global $wpdb;
$reg = "/(-e\d{13})?(-[0-9]+x[0-9]+)?\.(jpg|jpeg|png|gif)$/i";
$src1 = preg_replace($reg,'',$src);
if($src1 != $src){
$ext = pathinfo($src, PATHINFO_EXTENSION);
$src = $src1 . '.' .$ext;
}
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$src'";
$id = $wpdb->get_var($query);