문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top