1

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 ?

8
  • I'm not an SQL wiz, but it would probably involve UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.oldsiteurl.com', 'http://yourcdn.newsiteurl.com') WHERE post_type = 'attachment';
    – jgraup
    Commented Dec 29, 2015 at 17:10
  • 1
    Don't mess with the GUID: wordpress.stackexchange.com/a/90209/21376
    – s_ha_dum
    Commented Dec 29, 2015 at 17:16
  • 2
    Why do you want to update the GUID? They aren't URLs, they're unique identifiers.
    – Milo
    Commented Dec 29, 2015 at 17:16
  • 3
    A GUID Gallery? Worst Gallery Ever!
    – jgraup
    Commented Dec 29, 2015 at 17:29
  • 1
    Your theme code is horrific. The GUID is not an URL and should not be used as one (Follow the link in my previous comment)
    – s_ha_dum
    Commented Dec 29, 2015 at 17:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.