I have a custom field for User type where I can link an attachement ID. I'm trying to save the attachment ID programmatically and it looks like it works, because when I run get_field($my_field) I have the right value. However the changes are not seen in the backend or in rest api, it still show the old value. I'm baffled, what could I be doing wrong?
Here is my code:
//Update field with attachment ID and user_id
$cover_custom_field_key = "field_5e9ed645b9ec3"; //cover field
$cover_id = media_handle_sideload( $image_file, 0 );
update_field( $cover_custom_field_key, $cover_id, 2 ); //update field for user id=2
echo get_field($cover_custom_field_key, 2); // echo : /
But in the backend there is still the old link to another image, and in the rest response for wp-json/wp/v2/users/2 also:
"id": 2,
"name": "Mata Hari",
"url": "",
"description": "",
"acf": {
"practice_playlist": false,
"cover": "/"
}
I have a custom field for User type where I can link an attachement ID. I'm trying to save the attachment ID programmatically and it looks like it works, because when I run get_field($my_field) I have the right value. However the changes are not seen in the backend or in rest api, it still show the old value. I'm baffled, what could I be doing wrong?
Here is my code:
//Update field with attachment ID and user_id
$cover_custom_field_key = "field_5e9ed645b9ec3"; //cover field
$cover_id = media_handle_sideload( $image_file, 0 );
update_field( $cover_custom_field_key, $cover_id, 2 ); //update field for user id=2
echo get_field($cover_custom_field_key, 2); // echo : https://example.com/cover-image/
But in the backend there is still the old link to another image, and in the rest response for wp-json/wp/v2/users/2 also:
"id": 2,
"name": "Mata Hari",
"url": "",
"description": "",
"acf": {
"practice_playlist": false,
"cover": "https://example.com/abstract-colorful-geometric-banner-template-background/"
}
Ok got it, for user field actually one has to add "user_" before the id for it to work. So in my case:
update_field( $cover_custom_field_key, $cover_id, "user_2" );