Redirect to newly created post?

Support MB Frontend Submission Redirect to newly created post?Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #21829
    NickNick
    Participant

    I feel like I must be overlooking this information because it seems like a pretty obvious feature. How can I have a frontend submission form redirect to the new post that is created upon submission of the form?

    #21837
    Long NguyenLong Nguyen
    Moderator

    Hi Nick,

    We can use the action hook rwmb_frontend_after_process then redirect to the new post by using the function get_post_permalink().

    add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
        wp_safe_redirect( get_post_permalink(  $post_id ) );
        die;
    }, 10, 2 );
    

    For more information, please follow documentations.
    https://docs.metabox.io/extensions/mb-frontend-submission/#form-actions
    https://developer.wordpress.org/reference/functions/get_post_permalink/

    #32089
    Stephen C.Stephen C.
    Participant

    FYI: This no longer works now that the frontend form is submitted via ajax. In order to redirect to the post, you need to do something like this:

    // Redirect to the newly created post
    add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
        $url = get_post_permalink(  $post_id );
        echo json_encode(
            array(
                'success'=>true, 
                'data'=> array(
                    'message' => 'Your success message', 
                    'redirect' => $url
                )
            )
        );
        die;
    }, 10, 2 );
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.