Created
October 25, 2013 14:29
-
-
Save JackuB/7155562 to your computer and use it in GitHub Desktop.
WordPress: find all post thumbnails that match criteria // remove those unfitting
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 | |
$args = array('posts_per_page' => -1); // get all posts | |
$attachments = get_posts( $args ); | |
$allP = 0; | |
$wThumb = 0; | |
$great = 0; | |
$ok = 0; | |
$wrong = 0; | |
if ( $attachments ) { | |
foreach ( $attachments as $post ) { | |
$allP++; | |
if(has_post_thumbnail()) { | |
$wThumb++; | |
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); | |
$size = getimagesize($url); | |
if($size[0] >= 710 && $size[1] >= 355) { | |
$great++; | |
} elseif($size[0] >= 330 && $size[1] >= 165) { | |
$ok++; | |
} else { | |
$wrong++; | |
if($size[0] == 0) { | |
echo "Deleted post thumbnail for <a href=\"" . get_permalink() . "\">" . get_the_title() . "</a> because post thumbnail couldn't be found<br />"; | |
} else { | |
echo "Deleted post thumbnail for <a href=\"" . get_permalink() . "\">" . get_the_title() . "</a> because post thumbnail had size " . $size[0] . " × " . $size[1] . "<br />"; | |
} | |
//delete_post_thumbnail($post->ID); | |
} | |
} | |
} | |
echo "found <strong>" . $allP . "</strong> posts<br /><br />"; | |
echo "found <strong>" . $wThumb . "</strong> posts with thumbnails<br /><br />"; | |
echo $great . " are ok<br />"; | |
echo $ok . " are ok (for post listing)<br />"; | |
echo $wrong . " are too small or missing<br />"; | |
} | |
die; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment