2013-04-08 70 views
0

我創建了一個帶有自定義帖子選項的邊欄框,但我似乎無法使用其他帖子數據保存到數據庫。add_meta_box不保存到數據庫

<?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到發佈表,但數據並沒有交給數據庫。幫幫我!!!

+1

這種數據不會保存在帖子表中。我認爲所有這些都發布到了postmeta表格中......除非您知道自己在做什麼,否則您不應該在該表格中添加任何列... – jakobhans 2013-04-08 16:24:29

+0

您是對的,我現在在那裏看到數據。謝謝! – jardane 2013-04-08 16:26:04

+0

我會將它作爲答案發布。別客氣! – jakobhans 2013-04-08 16:26:43

回答

0

這種數據不會保存在帖子表中。我認爲所有這一切都在postmeta表中。

+0

是的,我只是想通了 – jardane 2013-04-08 18:05:33