WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After using a function to submit custom fields the standard redirection is not longer working. What we would like is that after the post has been insetered for the user to be redirected the standard wp_redirect is not at the moment working. I theorise this is because of the custom fields submission function.

The code

if ( is_user_logged_in() ) {
$my_post = array(
    'post_title' => $_SESSION['booking-form-title'],
    'post_date' => $_SESSION['cal_startdate'],
    'post_content' => 'This is my post.',
    'post_status' => 'publish',
    'post_type' => 'booking',
    'post_author' => $user_ID,
 $the_post_id = wp_insert_post( $my_post );

__update_post_meta( $the_post_id, 'duration', $_SESSION['booking-form-actual-duration'] );
__update_post_meta( $the_post_id, 'picture', $_SESSION['booking-form-picture'] );
__update_post_meta( $the_post_id, 'totalprice', $_SESSION['booking-form-total-price'] );
__update_post_meta( $the_post_id, 'activityduration', $_SESSION['booking-form-total-duration'] );
__update_post_meta( $the_post_id, 'totaldives', $_SESSION['booking-form-total-dives'] );

query_posts('post_type=services'); while (have_posts()) : the_post();
__update_post_meta( $the_post_id, 'producttitle'.get_the_ID(), $_SESSION['products-form-title'.get_the_ID()]); 
__update_post_meta( $the_post_id, 'productprice'.get_the_ID(), $_SESSION['products-form-price'.get_the_ID()]); 
__update_post_meta( $the_post_id, 'productduration'.get_the_ID(), $_SESSION['products-form-duration'.get_the_ID()]);
__update_post_meta( $the_post_id, 'productdives'.get_the_ID(), $_SESSION['products-form-dives'.get_the_ID()]);  
__update_post_meta( $the_post_id, 'productquantity'.get_the_ID(), $_SESSION['products-form-quantity'.get_the_ID()]); 

 $linkit = get_permalink($the_post_id);
else {;}

the wp_redirect is producing the following error Warning: Cannot modify header information - headers already sent by (output started at /home/divethe1/public_html/update/wp-content/themes/master/type-booking.php:18) in /home/divethe1/public_html/update/wp-includes/pluggable.php on line 890

Just so we are on the same page to change $the_post_id to $post_id negated the function and still does not perform the redirect. The function and procedure to make it can be found at WP insert post PHP function and Custom Fields

The objective is therefore to redirect the user to the page created by the wp_insert_post. If anyone can see where I have gone wrong, many thanks,


share|improve this question
What is line 18 of your type-booking.php? – Bainternet Feb 8 '11 at 18:47

Had you tried to output link and verify it is correct?

Also you should call die(); right after redirect.

share|improve this answer
@Robin - (extending your answer) Agreed, use a die( $linkit ); to verify that you're getting the proper link. Also, calling die() after wp_redirect makes sense – Zack Feb 8 '11 at 20:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.