Home Forums Front-end Issues Stop acf/save_post in its tracks


Stop acf/save_post in its tracks

  • So I have a simple acf_form on the front end which pulls a couple of custom fields from a post, specifically a name and email address. When the form is submitted an email is sent to that email address. What I’d like to do now though is invite the user to enter an alternative email address and then choose whether the new value should be saved on submission or not. This is don’t with a checkbox.

    I’m all good up to the point where I’m conditionally hooking into the save_post process according to which acf_form is being submitted and whether the box has been checked. However, I can’t figure out a way to just STOP the save_post process. I’ve tried using high priority, I’ve tried returning null, false and empty $_POST. I’ve even tried returning false values for various hidden values including _acf_validation, _acf_changed and even _acf_post_id but despite all my efforts the post is still updated.

    Is there any way that I can just abort the process and prevent the save from happening if the conditions are met?


  • You need to hook into acf/save_post before ACF saves values, so with a priority of < 10

    add_action('acf/save_post', 'YOUR_FUNCTION', 1);

    Then you need to access the values in $_POST['acf'] because the fields have not been saved yet. Once you are done then you can unset $_POST['acf'] and this will cause ACF to not save anything.

    Doing any of this after ACF has saved the values will be to late.

  • Boom. Thanks, John. I arrived at the same method after testing changing about every other value in the $_POSTed array but still wasn’t sure if I was missing something. Thanks a lot for getting back to me.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.