Support

Account

Home Forums Backend Issues (wp-admin) acf/save_post Generating Duplicates Reply To: acf/save_post Generating Duplicates

  • I commented out the action and it no longer repeats (when editing a ‘testimonial’ post type), so it must be something in the function.

    I have started changing the function to run ahead of $_POST[‘acf’], but the issue remains. Please see my updated code below…

    // ACF Auto Titles
    function my_post_title_updater( $post_id ) {
      if ( get_post_type( $post_id ) == 'testimonial' ) {
    
        $name_field = $_POST['acf'][field_556ea5ac8c15b]; // Name
        $testimonial_field = $_POST['acf'][field_556ea5c68c15c]; // Testimonial
    
        $my_post = array(
          'ID' => $post_id,
          'post_title' => $name_field . ' - \'' . $testimonial_field . '\'',
          'post_name' => $post_id
        );
    
      } elseif ( get_post_type( $post_id ) == 'client' ) {
    
        $my_post = array();
        $my_post['ID'] = $post_id;
        $my_post['post_title'] = get_field( 'name', $post_id );
        $my_post['post_name'] = $my_post['post_title'];
    
      } elseif ( get_post_type( $post_id ) == 'project' ) {
    
        $my_post = array();
        $my_post['ID'] = $post_id;
        $my_post['post_title'] = get_field( 'name', $post_id );
        $my_post['post_name'] = $my_post['post_title'];
      }
    
      wp_update_post( $my_post );
      
    }
    
    add_action('acf/save_post', 'my_post_title_updater', 1);