这段代码应该首先是有条件的,然后是表单输出,因为在设置了头并正在更新后,您不能使用wp\\u重定向,所以请使用update_post_meta
而不是add_post_meta
.
尝试:
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>