Home › Forums › Backend Issues (wp-admin) › Disabled Field doesn't work if it has Conditional Requirements › Reply To: Disabled Field doesn't work if it has Conditional Requirements
Hi,
I know this is a couple of years old, but hopefully this will save someone else some time.
The work around I wrote uses the ACF filters to make sure disabled fields could not be accidentally overwritten by an admin page that was left open and then saved after the meta has been updated elsewhere in the code. Example:
function my_acf_update_value( $value, $post_id, $field, $original ) {
if($field['disabled']){
// if the field is supposed to be disabled, return the live meta value
$value = get_post_meta($post_id,$field['name'],true);
}
return $value;
}
// Apply to all fields.
add_filter('acf/update_value', 'my_acf_update_value', 10, 4);
Now, if you want to update the meta value elsewhere, you will now need to use update_post_meta() as update_field() will use the above filter.
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.