Why wp_update_post() does not update GUID?

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'
];
    
wp_update_post($post);

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]);

Leave a Comment