I have a form that uploads images and i want to update the GUID to be the attachment file url after WP generates the metadata.
I tried to use wp_update_post
, but seems that is not updating the guid
.
$attachments = get_posts($post_data);
if ($attachments) {
// attach images to gallery
foreach ($attachments as $attachment) {
wp_update_post(array(
'ID' => $attachment->ID,
'post_status' => 'inherit',
'post_parent' => $gallery_post_id,
'guid' = wp_get_attachment_url($attachment->ID);
)
);
}
}
Any suggestions ?
UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.oldsiteurl.com', 'http://yourcdn.newsiteurl.com') WHERE post_type = 'attachment';
GUID
: wordpress.stackexchange.com/a/90209/21376