Home › Forums › Feature Requests › Read-Only Field › Reply To: Read-Only Field
Perhaps not the most elegant way, but hey, it works!
/**
* Prevents a field from being updated from the panel in ACF.
* Useful for business-critical fields that must only by updated internally, but still need to be visible on the admin panel.
*/
function prevents_field_from_being_updated_from_the_panel($value, $post_id, $field) {
$backtraces = debug_backtrace();
foreach ($backtraces as $backtrace) {
if (!empty($backtrace['function']) && $backtrace['function'] == 'update_field') {
return $value;
}
}
return get_field('field_5b5fcd08f9ecf', $post_id, false); # Change field_{key} to your field key/name
}
# If you have the field Key:
add_filter('acf/update_value/key=YOUR_FIELD_KEY', 'prevents_field_from_being_updated_from_the_panel', 10, 3);
# If you prefer to use field name:
# add_filter('acf/update_value/name=YOUR_FIELD_NAME', 'prevents_field_from_being_updated_from_the_panel', 10, 3);
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.