Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puneetkay/f63c7e29f1075062e5006b4e837fa9d8 to your computer and use it in GitHub Desktop.
Save puneetkay/f63c7e29f1075062e5006b4e837fa9d8 to your computer and use it in GitHub Desktop.
Remove generated attachment thumbnails from wordpress database.
global $wpdb;
$query = "SELECT meta_value, meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata'";
$result = $wpdb->get_results($query);
foreach ($result as $item) {
$meta = unserialize($item->meta_value);
unset($meta['sizes']);
$wpdb->update( 'wp_vira_postmeta', array('meta_value' => serialize($meta)), array('meta_id' => $item->meta_id) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment