add_meta_box没有保存到数据库

时间:2013-04-08 16:21:20

标签: php wordpress plugins save

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

<?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表,但数据没有将其转移到数据库。 HELP !!!

1 个答案:

答案 0 :(得分:0)

此类数据不会保存在帖子表中。我想所有这些都归到了postmeta表。

相关问题