Last active
December 3, 2018 12:31
-
-
Save YOzaz/a16b75ba3ca7a382bebf4edab11a9104 to your computer and use it in GitHub Desktop.
Check if image exists using `wp_posts` table
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
<?php | |
global $wpdb; | |
$image_src = wp_upload_dir()['baseurl'] . '/' . _wp_relative_upload_path( $filename ); | |
$query = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE guid='$image_src'"; | |
$count = intval($wpdb->get_var($query)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment