You need to put the form processing part of the code at the top of the page before anything else and
wp_redirect(get_permalink($pid)); exit;
Right after
$pid = wp_insert_post($new_post);
You need to put the form processing part of the code at the top of the page before anything else and
wp_redirect(get_permalink($pid)); exit;
Right after
$pid = wp_insert_post($new_post);