max-kk
11/28/2010 - 7:27 PM

Remove generated attachment thumbnails from wordpress database.

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) );
}