Support

Account

Home Forums Front-end Issues How do you create post_title from another field(s) in ACF Pro? Reply To: How do you create post_title from another field(s) in ACF Pro?

  • It turned out to be quite simple. Just combine the PRO version and the older acf/pre_save_post like this:

    1.
    In the template, leave out the ‘new_post’ field:

    $options = array(
    	'id' => 'acf-form',
    	'post_id' => new_post, //if new post
    	/*Leave this field out of the array!!
    	'new_post' => array(
    			'post_title' => 'Test'
    			),
    	
    	*/
    	//...you other options
    );

    2.
    In the acf/pre_save_field in functions/template, create the post here instead:

    function my_pre_save_post( $post_id ) {
     
          // Create a new post
          $post = array(
          	'post_status'  => 'publish' ,
       	//Use the ACF fields to create the title or any other field.
          	'post_title'  => $_POST['acf']['field_586e6ada97b7b'] . ' ' . $_POST['acf']['field_586e6ae197b7c']
          );  
    
          // insert the post
          $post_id = wp_insert_post( $post );
       	 // return the new ID
       	 return $post_id;
        }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 1, 1 );

    As described earlier, only the ACF fields are included in the $_POST.