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?

  • Forgot to add the code, here it comes (I tried delete and then the update):

    function my_acf_save_post($post_id) {
    if (get_field(‘are_we_counting_participants’, $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(‘number_of_participants’, NULL, $post_id);
    // or delete the value of the field
    // delete_field(‘number_of_participants’, $post_id);
    }
    }
    add_action(‘acf/save_post’, ‘my_acf_save_post’, 20);