I’m using an ACF Form in the front-end of a WordPress website. The ACF form in ‘Post A’ creates a new post ‘Post B’. I am trying to create a function that will update an ACF field in Post A (I will then use this to remove the form from Post A so that it can only be submitted once). I have been trying to use an acf/save_post action to update the field but this seems to only effect Post B and not Post A. Here is my code:
<?php
add_action('acf/save_post', 'update_post_status', 20);
function update_post_status( $post_id ) {
if( get_post_type($post_id) !== 'mypost' ) {
return;
}
update_field('form_submitted', 'yes');
}
?>
2
Answers
Ive had success with using
acf/validate_save_post
rather thanacf/save_post
as this fires before the new post is created so the function still refers to the original post.I think that you use the incorrect hook for this task
acf-save_post
You can use ‘save_post‘
For example