Last active
June 30, 2021 08:59
-
-
Save danemorgan/a8e6b5e505104e9541fec4d2ed91a229 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Get the attachment ID of an image from it's URL. | |
* | |
* @param string $image_url The URL for the image you need an id for. | |
* | |
* @return mixed | |
*/ | |
function theme_get_image_id($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