This code should be conditional first and then form output since you can’t use wp_redirect after headers are set and you are updating so use update_post_meta
instead of add_post_meta
.
Try:
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "edit_post" && isset($_POST['pid'])) {
$the_post = get_post($_POST['pid']);
$the_post = array();
$the_post['post_content'] = $_POST['description'];
$the_post['data'] = array($_POST['data']);
$pid = wp_update_post($the_post);
update_post_meta($pid, 'rating', $the_post['data'], true);
$link = get_permalink( $pid );
wp_redirect($link);
}
<!-- edit Post Form -->
<div id="postbox">
<form id="edit_post" name="edit_post" method="post" action="">
<p><label for="description">Description</label><br />
<textarea id="description" name="description" ><?php echo $post_to_edit->post_content; ?></textarea>
</p>
<!-- wine Rating -->
<fieldset class="data">
<label for="data">data</label>
<input type="text" value="" id="data" size="60" tabindex="20" name="data"><?php echo (!empty($val = get_post_meta($post_to_edit->ID,'rating',true))) ? $val : ''; ?></textarea>
</fieldset>
<p align="right"><input type="submit" value="Edit" tabindex="6" id="submit" name="submit" /></p>
<input type="hidden" name="action" value="edit_post" />
<input type="hidden" name="pid" value="<?php echo $post_to_edit->ID; ?>" />
<?php wp_nonce_field( 'edit-post' ); ?>
</form>
</div>