wp_redirect() function is not working

Two things wrong here:

  1. Don’t use $post->guid as an url
  2. You must exit() after using wp_redirect() (see the Codex)

    wp_redirect() does not exit automatically and should almost always be followed by exit.

To redirect to your new post’s page:

//..... code as in question
$post_id = wp_insert_post($new_post);
$url = get_permalink( $post_id );
wp_redirect($url);
exit();

Leave a Comment