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);
Hi John!
Thank you very much for your kind help! It almost worked! The b value (Are we counting participants) is set to NULL. But I realised that the true/false field does not work with the Condition Logic setting (In my field number of participants (b) I have: Show this field if -> Are we counting participants (a) -> Value is equal to -> Checked).
But when checked it does not show field b (number of participants).
Please share your ideas of what I could if possible.
Wish you a great day!
David
Hi John,
Thank you very much for your advice. I tried the following code unfortunately without luck.. Nothing changes. Im a beginner at this so I was wondering if you or someone else can advice me on what is wrong?
function my_acf_save_post( $post_id ) {
// Bail early if no data sent.
if( empty( $_POST[‘are_we_counting_participants’] ) ) {
return;
}
// Get values.
$values = $_POST[‘are_we_counting_participants’];
// Update with new value.
if( $values == ‘no’ ) {
update_field(‘number_of_participants’, NULL);
}
}
add_action(‘acf/save_post’, ‘my_acf_save_post’);