Get attachment ID by image url — wordpress

Posted: January 8, 2015 in WordPress

$taxonomy_image_url = get_option('z_taxonomy_image'.$term_id);
 $attachment_id = developer_attachment_id_by_url($taxonomy_image_url);

function developer_attachment_id_by_url($image_src) {

global $wpdb; $query = "SELECT ID FROM {$wpdb->posts} WHERE guid = '$image_src'"; $id = $wpdb->get_var($query); return (!empty($id)) ? $id : NULL;

}
Advertisements

Comments are closed.