0

我创建了一个带有自定义帖子选项的侧边栏框,但我似乎无法将其余的帖子数据保存到数据库中。

<?php
/*
Plugin Name: Column Height Calculator
Plugin URI: #
Description: calculates the height of the column
Version: 0.1
Author: Ben Crawford
Author URI:
*/

add_action('admin_menu', 'my_post_options_box');

function my_post_options_box() {
add_meta_box('post_info', 'Column Height Info', 'custom_post_info', 'post', 'side', 'high');
}

//Adds the actual option box
function custom_post_info() {
global $post;
?>
<fieldset id="mycustom-div">
<div>
<p>
<label for="column_type" >Column Type:</label>
<br />
<select name="column_type" id="column_type">
  <option value="JBC">Justified Body Copy</option>
  <option value="LRC">Left Raggid Copy</option>
</select>
<br />
<br />
<label for="header_size">Header Size:</label>
<br />
<input type="text" name="header_size" id="header_size" value="<?php echo get_post_meta($post->ID, 'header_size', true); ?>">
</p>
</div>
</fieldset>
<?php
}

add_action('save_post', 'custom_add_save');
function custom_add_save($postID){
// called after a post or page is saved
if($parent_id = wp_is_post_revision($postID))
{
$postID = $parent_id;
}

if ($_POST['column_type']) {
update_custom_meta($postID, $_POST['column_type'], 'column_type');
}
if ($_POST['header_size']) {
update_custom_meta($postID, $_POST['header_size'], 'header_size');
}
}

function update_custom_meta($postID, $newvalue, $field_name) {
// To create new meta
if(!get_post_meta($postID, $field_name)){
add_post_meta($postID, $field_name, $newvalue);
}else{
// or to update existing meta
update_post_meta($postID, $field_name, $newvalue);
}
}
?>

我手动将 column_type 和 header_size 添加到 post 表中,但数据没有进入数据库。帮助!!!

4

1 回答 1

1

这种数据不会保存在 post 表中。我认为这一切都归于 postmeta 表。

于 2013-04-08T16:26:57.623 回答