Support

Account

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.