skip to Main Content

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


  1. you can use delete_field( 'project_address_1', $post_id ); instead updating with null value

    Login or Signup to reply.
  2. Can you try this

    ACF Field – https://www.advancedcustomfields.com/resources/delete_field/

    delete_field( 'my_field', $post_id );
    

    Like delete_field( 'color', 123 );

    Post meta – https://developer.wordpress.org/reference/functions/delete_post_meta/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search