Support

Account

Home Forums Front-end Issues Redirect after form submit Front End new post

Helping

Redirect after form submit Front End new post

  • For some reason I can’t get this to work, The page is getting created, but I get redirected to a blank page, my current Front End page looks like:

    
    <?php                    
      $args = array(
        'post_id' => 'new_1',
        'field_groups' => array( 357 ),
        'submit_value' => 'Submit Story', 
        'return' => '%post_url%?foo=bar'
       );
    acf_form( $args );
    ?>
    

    And My Functions File:

    
    //ACF FORM ARGUMENT
    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new_1' )
        {		
    		return $post_id;
    	}
    	
    	// Create a new post
    	$post = array(
    		'post_status'  => 'publish' ,
    		'post_title'  => $_POST['fields']['field_54f5894e01b06'],
    		'post_content'	=>	$_POST['fields']['field_54f5897401b07'],
    		'post_type'  => 'shortstory',
    		'post_parent'   =>  $_POST['fields']['field_54f596ac44e2b']
    	);  
    
    	// insert the post
    	$post_id = wp_insert_post( $post ); 
    	
    	// update $_POST['return']
    	$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
      
    	return $post_id;
    }
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    

    Any help would be much appreciated.

  • This reply has been marked as private.
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Redirect after form submit Front End new post’ is closed to new replies.