Meta Box
Support › MB Frontend Submission › Redirect to newly created post?Resolved
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?
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().
rwmb_frontend_after_process
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/
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 );