How to change _wp_attachment_metadata specific value in SQL?

You could do this via PHP instead of SQL, just get the existing metadata and change what you need to, it will handling the serializing for you:

$newwidth="250"; // or whatever it is
$attachments = get_posts(array('post_type'=>'attachment');
foreach ($attachments as $attachment) {
    $id = $attachment->ID;
    $metadata = wp_get_attachment_metadata($id);
    $metadata['width'] = $newwidth;
    wp_update_attachment_metadata($id,$metadata);
}

But really, you may do better use the Regenerate Thumbnails Plugin which may fix this and regenerate the different thumbnail sizes at the same time.

Leave a Comment