sorry – I forgot to mention that this is a JS code. this code will only be loaded on the CPT with this fields.
I had the same problem with a disabled post_object field: its value is lost on save.
Ended with this workaround:
add_filter('acf/update_value/name=companies', function ($value, $user_id, $field, $original) {
//debug
//error_log('Saving companies: ' . json_encode($value) . ' ' . $user_id);
//error_log('Last value: ' . get_field('companies', $user_id));
/*
* Workaround for read only field where its value is reset
* on the edit profile screen to ''.
*
* We set its value always to an array [] (empty or with companies).
*/
if ($value === '') {
$value = get_field('companies', $user_id);
}
return $value;
}, 10, 4);
Quite a hack but it works now fine.