0

I am trying to run a function on post update by checking if an ACF is equal to something.

I'm checking if the ACF value is equal to new or closed.

when i change it from value new to closed and save it doesn't run but if i save the post again when the post is at closed it does run.

function check_values($post_ID){
    if(get_field('status', $post_ID ) == "closed") {
        sendSMS();
    }
}

add_action( 'post_updated', 'check_values', 10, 3 ); //don't forget the last argument to allow all three arguments of the function

Is there something I'm missing about this? I want to avoid saving each post twice.

Thank you

1 Answer 1

1

Please try using acf/save_post action that will hook in after ACF data has been saved.

add_action('acf/save_post', 'check_values');

function check_values($post_id){
    if(get_field('status', $post_id ) == "closed") {
        sendSMS();
    }
}
1
  • It works! thanks a lot
    – Asaf Hadad
    Commented Mar 9, 2020 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.