Support

Account

Home Forums Front-end Issues Post_title not being saved

Unread

Post_title not being saved

    • udarts

    • August 9, 2019 at 10:19 pm

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.