Home › Forums › Backend Issues (wp-admin) › save_post always fired twice when ACF fields present › Reply To: save_post always fired twice when ACF fields present
Your problem is that the action hook that you are using happens before the hook used by acf
/** This action is documented in wp-includes/post.php */
do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
/** This action is documented in wp-includes/post.php */
do_action( 'save_post', $post->ID, $post, true );
ACF is triggered on the save_post hook with a priority of 10. This means that when your action runs ACF has not yet saved any values. The first time your action runs there are no values and thereafter each times that your action runs it is getting the old value instead of the new value.
You have 2 choices.
1) Get the value from the submitted value in $_POST[‘acf’] see discussion about applied before save for acf/save_post https://www.advancedcustomfields.com/resources/acf-save_post/
2) You could use the save_post hook with a priority > 10.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.