Why wp_update_post() does not update GUID?
-
15-04-2021 - |
Domanda
I'm trying to update GUID on a attachment. But somehow it's not working neither it's throwing any error.
Example Code:
$my_post = [
'ID' => 45,
'guid' => 'https://example.com/foo.png'
];
wp_update_post( $my_post );
WordPress does not seem to update the GUID.
But if we try update other values such as post_parent
, it works fine.
Why is that?
Soluzione
I tried a lot of things but somehow WordPress won't let me update GUID using wp_update_post() function.
But we can update GUID using SQL query. The best approach would be:
global $wpdb;
$wpdb->update($wpdb->posts, ['guid' => 'your_new_guid'], ['ID' => 45]);
your_new_guid = what you want to update
ID = attachment/post ID needs to be updated
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange