Home › Forums › Feature Requests › Read-Only Field › Reply To: Read-Only Field
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.