Trying to update GUID on a attachment using the wp_update_post() function but its not updating GUID nor its throwing any error.

Example code:

$post = [
    'ID'   => 45,
    'guid' => 'https://example.com/foo.png'
  • Why need to update guid?
    – birgire
    Commented Mar 29, 2019 at 7:20
  • I'm not updating GUID for actual post but for attachment. I am planning to serve images from a image hosting site rather than serving from me. It works fine but I need to update GUID for that.
    – Harry
    Commented Mar 29, 2019 at 7:25
  • Why? You are aware that the GUID has nothing to do with the post's permalink, right? It's just an identifier. Changing the GUID won't change a post's URL. Commented Mar 29, 2019 at 11:24
  • I am not changing post permalink. It's for different thing. Anyway I figured it out.
    – Harry
    Commented Mar 29, 2019 at 12:22

1 Answer 1


Turns out WordPress do not recommend updating GUID thus its disallowed.

But we can update it using sql query:

global $wpdb;
$wpdb->update($wpdb->posts, ['guid' => $newGUID], ['ID' => $postID]);
  • I'm sure it would have been intentionally disallowed to prevent changes to it, while it's fine for attachments, preventing changing it in most cases was probably a good idea given it's not supposed to change.
    – majick
    Commented Mar 29, 2019 at 9:43
  • Yes. changing GUID is not wordpress recommends. But sometimes it has/needs to be changed.
    – Harry
    Commented Dec 22, 2019 at 16:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.