Issue
I need to update "_wp_attachment_metadata" in wppostmeta tabele of image that was copy&paste to new localization.
Since WP documentation isn't clear for me, I'd like to ask what should I input to $data argument?
wp_update_attachment_metadata( $post_id, $data );
$post_id is pretty clear, I can take it from database. What about $data?
https://codex.wordpress.org/Function_Reference/wp_update_attachment_metadata
EDIT
I have tried this (98 is post_id/attachment-page id)
$data = wp_get_attachment_metadata( 98 );
wp_update_attachment_metadata( $post_id, $data );
but it doesn't works I've also tried something like:
`while ($row = $post_id->fetch_assoc() and $media = $meta_value->fetch_assoc() ) {
$row_id = $row['post_id'];
$media_name = $media['meta_value'];
update_post_meta( $row_id , '_wp_attachment_metadata' , $media_name );
}`
and it works I can see images/thumbnails, but when I try to edit image it says "No image data in file. Please send the image to the server again."
Solution
From the documentation, it is the (serialized) meta data for that image. Basically it's a biggish associative array that describes the image. When you use that method you have to provide all of the data values (not just the ones you know you want to change).
Changing it might look something like this:
$data = wp_get_attachment_metadata( $attachment_id); // get the data structured
$data['width'] = 680; // change the values you need to change
wp_update_attachment_metadata( $attachment_id, $data ); // save it back to the db
You can see what the associative array looks like in the documentation for wp_update_attachment_metadata
Answered By - vlasits
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.