Support

Account

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);
      }
    }