Support

Account

Home Forums Backend Issues (wp-admin) Reset ACF Field after Publish Post

Helping

Reset ACF Field after Publish Post

  • Hi … i have created 3 ACF fields to be displayed on every post edit screen.

    Basically when i add and publish a new post, i want to click a checkbox “Send Email” which will display the email address field and email content field. Here i will add an email address and enter the email content. On clicking “Publish” or “Update” button for this post, i have added code into the functions.php which triggers at the ‘transition_post_status’ action to send the email as specified only when the “SEND EMAIL” field is ticked “YES” (true).

    The thing is i want to reset the “SEND EMAIL” field back to “NO” or false (it is a true/false toggle field) after the email is sent to avoid subsequent emails being triggered in case of clicking the post update button again. I tried adding an update_field(‘send_email’, FALSE, post_id) in the above email notification code. However on clicking the post update/publish button, the field does not get reset back to its original value.

    Any idea what i could be doing wrong here? or am i using a wrong action trigger.

    Appreciate some thoughts on this. Thanking you in advance!

    (apologies if i wasnt too clear above, please ask me for any clarification)

  • You should try using the acf/save_post action. If I’m not mistaken ACF saves field content after WP finishes updating and this would probably include the transition_post_status hook. This means that your update field is probably working but that ACF is saving the value after you have updated it. Actually, I’m not 100% certain of this without testing, but it’s the first thing I’d look at.

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

You must be logged in to reply to this topic.