Home › Forums › General Issues › Set a field's value to null or other value? › Reply To: Set a field's value to null or other value?
The first thing you need to do is to set up the two fields
field a = true false field
field b = this field has conditional logic to only show if field a is true, set the default value of field b to whatever you want as the default.
add_action('acf/save_post', 'my_acf_save_post;, 20);
function my_acf_save_post($post_id) {
if (get_field('field_a', $post_id)) {
// value is true
// do nothing, value is set to the default or something new was entered
} else {
// value is false
// you can do one of the following
// set field b to a default value
update_field('field_b', 'your value', $post_id);
// or delete the value of the field
delete_field('field_b', $post_id);
}
}
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.