Last active
December 3, 2018 12:40
-
-
Save YOzaz/3a8ee262e1bf817c557535474ff5d3a3 to your computer and use it in GitHub Desktop.
Check if image exists using `wp_postmeta` 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; | |
$query = 'SELECT `wp_posts`.`ID`, `wp_posts`.`guid`, `wp_postmeta`.`meta_value` | |
FROM `wp_posts`, `wp_postmeta` | |
WHERE `post_type` = "attachment" | |
AND `wp_posts`.`ID` = `wp_postmeta`.`post_id` | |
AND `wp_postmeta`.`meta_key` = "_wp_attachment_metadata" | |
AND `wp_postmeta`.`meta_value` LIKE \'a:%:{s:5:"width";i:$$$PIXELS_WIDTH$$$;s:6:"height";i:$$$PIXELS_HEIGHT$$$;s:4:"file";s:%:"%$$$FILENAME$$$"%\''; | |
$query = str_replace('$$$PIXELS_WIDTH$$$', $width, $query); | |
$query = str_replace('$$$PIXELS_HEIGHT$$$', $height, $query); | |
$query = str_replace('$$$FILENAME$$$', $filename, $query); | |
$results = $wpdb->get_results( $query, OBJECT ); | |
if( count( $results ) > 0 ) | |
// something found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment