Support

Account

Home Forums General Issues Front end post creation, redirect after save

Solving

Front end post creation, redirect after save

  • I love the front-end form feature in ACF, it’s been a lifesaver for a recent project of mine.

    I do have one query though, how can I redirect a user to the newly created post once they’ve saved their post?

    This is my function if that helps solve the problem;

    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
     
        // Create a new post
        $post = array(
            'post_status'  => 'publish' ,
            'post_title' => $_POST['fields']['field_53092f8a31827'],
            'post_type'  => 'profile' ,
        );  
     
        // 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 the new ID
        return $post_id;  
    
     
    }
     

    Thanks in advance

  • Hi @poisontonomes

    You can modify $_POST['return'] with your URL.

    Thanks
    E

  • Apologies for my brain,

    But could you give an example?

    At the moment i’m playing with this:
    $_POST[‘http://www.google.com’%5D = add_query_arg( array(‘post_id’ => $post_id), $_POST[‘http://www.google.com’%5D );

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Front end post creation, redirect after save’ is closed to new replies.