I am hoping someone could please assist, I need to delete a field when a status goes to complete for a post, below is the code, right now this works but it always changes the field to null when the post updates it doesn’t matter what the status is. I need it to only delete the value when the status is complete.
add_action( 'acf/save_post', 'my_acf_save_post_7',10 );
function my_acf_save_post_7( $post_id ) {
$value = get_field( 'status', $post_id );
if ( $value = 'complete' ) {
update_field( 'project_address_1', null, $post_id );
}
}
2
Answers
you can use
delete_field( 'project_address_1', $post_id );
instead updating with null valueCan you try this
ACF Field – https://www.advancedcustomfields.com/resources/delete_field/
Like
delete_field( 'color', 123 );
Post meta – https://developer.wordpress.org/reference/functions/delete_post_meta/