Support

Account

Home Forums Front-end Issues Post_title not being saved

Unread

Post_title not being saved

  • I know this is a topic that has been mentioned a lot, but I tried multiple “solutions” at no luck.

    So I would like a second pair of eyes to check what I miss.
    I have a acf form at frontend and want to have the first and lastname as title.
    The rest of the fields is stored, but the title is not stored.

    Here is the code I use:

    
    function my_pre_save_post( $post_id ) {
    
    	// check if this is to be a new post
    	if( $post_id != 'new_post' ) {
    
    		return $post_id;
    
    	}
    	if (isset($_POST['my_dn'])) {
    
    		$title = $_POST['acf']['field_5d49dc8b9a31e'] . " " . $_POST['acf']['field_5d49dd419a320'];
    		// Create a new post
    		$post = array(
    			'id' => $post_id,
    			'post_status'  => 'publish',
    			'post_title' => $title,
    			'email' => $_POST['acf']['field_5d49dcb49a31f'],
    			'bedrag' => $_POST['acf']['field_5d49dd749a321'],
    			'periodiek' => $_POST['acf']['field_5d49de569a322'],
    		);
    	
    		// // 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');
    

    Cheers

Viewing 1 post (of 1 total)

The topic ‘Post_title not being saved’ is closed to new replies.