Support

Account

Home Forums General Issues ACF save post, check if new post Reply To: ACF save post, check if new post

  • Post status will not tell you whether the post is new or not, this will only hold a registered status https://codex.wordpress.org/Post_Status.

    The post will always exist when acf/save_post is run because acf/save_post happens on ‘save_post’ with a priority of 10. At this point in the process the post is already save and/or updated.

    If you are going to be saving and updating from both the front and back ends then the only solution is to use save_post.

    Unless there is something else that you are doing that can tell you if it’s new or not. Something that you are doing to the post or the fields that you can test to see if it is already done or not. Or you could could create another wp meta field to hold a flag.

    
    function my_acf_save_post( $post_id ) {
      $flag = get_post_meta($post_id, 'my_flag_field', true);
      if ($flag == 'already done') {
        // this is not a new post
        return;
      }
      // set flag
      update_post_meta($post_id, 'my_flag_field', 'already done');
    
      // do other stuff to new post
    }
    add_action('acf/save_post', 'my_acf_save_post', 20);