Support

Account

Home Forums ACF PRO Auto generate title from custom fields Reply To: Auto generate title from custom fields

  • I’m having the same issue. It was working perfectly fine in v4, but something has broken in v5.

    This is my code on my page template to show the form:

    
    <?php acf_form(array(
          'field_groups' => array('group_59398ef696c50'),
      		'post_id'		=> 'new_universe',
      		'post_title'	=> false,
      		'post_content'	=> false,
      		'new_post'		=> array(
      			'post_type'		=> 'universe',
      			'post_status'	=> 'publish'
      		),
          'submit_value' => 'Create'
    		)); ?>
    

    and this is my pre_save_post function

    
    function create_universe_form( $post_id ) {
      // bail early if not a new post
      if( $post_id !== 'new_universe' ) {
        return $post_id;
      }
      // vars
      $title = $_POST['acf']['field_59398f1d71f62'];
      // Create a new post
      $post = array(
        'post_status'	=> 'publish',
        'post_type'		=> 'universe',
        'post_title'	=> $_POST['acf']['field_59398f1d71f62'],
      );
      // insert the post
      $post_id = wp_insert_post( $post );
      // Update $_POST Return
      $url = get_permalink($post_id);
    	$_POST['return'] = ($url);
      // return the new ID
      return $post_id;
    }
    
    add_filter('acf/pre_save_post' , 'create_universe_form', 1, 1 );
    

    Currently, it is properly saving/updating the URL/slug, but not the actual title.