Last active
December 24, 2015 13:39
-
-
Save ayublin/6806911 to your computer and use it in GitHub Desktop.
Regenerate attachment meta data
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 all attachments | |
$attachments = get_posts( array( | |
'post_type' => 'attachment', | |
'posts_per_page' => -1, | |
) ); | |
foreach($attachments as $attach) | |
{ | |
// get upload base dir | |
$upload = wp_upload_dir(); | |
$upload = $upload['basedir']; | |
// get file relative path | |
$begin = strrpos($attach->guid, 'uploads/') + strlen('uploads/'); | |
$path = trailingslashit($upload) . substr($attach->guid, $begin); | |
// generate and update meta data | |
$data = wp_generate_attachment_metadata( $attach->ID, $path ); | |
wp_update_attachment_metadata( $attach->ID, $data ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment