Support

Account

Home Forums Front-end Issues Front-end Form: Redirect after Save Reply To: Front-end Form: Redirect after Save

  • Hi StormTrooper,

    this code works for me:

    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    function my_pre_save_post( $post_id ) {
        global $post;
    	
    	if($post->post_name == 'some-post') {
    	    // Create a new post
    	    $post = array(
    	        'post_status'  => 'publish' ,
    	        'post_title'  => 'some-title',
    	        'post_type'  => 'some-post-type',
    	    );  
    	 
    	    // insert the post
    	    $post_id = wp_insert_post($post); 
    		
    		// update custom field
    		update_post_meta($post_id, 'some-customfield', $post_id);
    						 
    		do_action('acf/save_post', $post_id);
    
         	//do_action('acf/save_post' , $post_id);
    	    wp_redirect( '/some-page-to-redirect/', 301);
    		exit;	
    	}			
    }
    

    Check your site for Javascript errors if the function does not work… 🙂

    Greetings
    Christian