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?

  • This works for me

    add_action('acf/save_post', 'custom_acf_save_post', 20);
    function custom_acf_save_post( $post_id ) {
    	
    	// bail early if no ACF data
    	if( empty($_POST['acf']) ) {
    		
    		return;
    	}
    
    	$data['ID'] = $post_id;
    	// Combine first name and last name to create a title
    	$title = trim($_POST['acf']['field_55687a737d49f']) . " " . trim($_POST['acf']['field_55687a917d4a0']);
    	$data['post_title'] = $title;
    	$data['post_name'] = sanitize_title( $title );
    
    	wp_update_post( $data );
    
    }