Custom Fields
Re-Envisioned
Support MB Frontend Submission Redirect to newly created post?

  • Creator
    Topic
  • #21829
    Resolved Nick
    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #21837
    Long 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.
    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 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.