0
我似乎有我的元框保存问题,不完全确定我做错了什么。任何帮助将不胜感激!特定模板文件中没有保存的Wordpress元框
我的继承人功能文件:
add_action('add_meta_boxes', 'cd_meta_box_add');
function cd_meta_box_add()
{
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
if ($template_file == 'golf.php')
{
add_meta_box (
'golf-times',
'Golf Opening Times & Prices',
'cd_meta_box_cb',
'page',
'normal',
'high'
);
}
}
function cd_meta_box_cb($post)
{
$values = get_post_custom($post->ID);
$times = isset($values['golf_meta_box_times']) ? esc_attr($values['golf_meta_box_times'][0]) : '';
$prices = isset($values['golf_meta_box_prices']) ? esc_attr($values['golf_meta_box_prices'][0]) : '';
wp_nonce_field('golf_meta_box_nonce', 'meta_box_nonce');
?>
<div style="overflow: hidden;">
<div style="width: 45%; float: left;">
<p><label for="golf_meta_box_times">Opening Times</label></p>
<p><textarea type="text" name="golf_meta_box_times" id="golf_meta_box_times" rows="5" style="width: 90%;" value="<?php echo $times; ?>"> </textarea></p>
</div>
<div style="width: 45%; float: left;">
<p><label for="golf_meta_box_prices">Prices</label></p>
<p><textarea type="text" name="golf_meta_box_prices" id="golf_meta_box_prices" rows="5" style="width: 90%;" value="<?php echo $prices; ?>"> </textarea></p>
</div>
</div>
<?php
}
add_action('save_post', 'cd_meta_box_save');
function cd_meta_box_save($post_id)
{
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if(!isset($_POST['meta_box_nonce']) || !wp_verify_nonce($_POST['meta_box_nonce'], 'golf_meta_box_nonce')) return;
if(!current_user_can('edit_post')) return;
$allowed = array(
'a' => array(
'href' => array()
)
);
if(isset($_POST['golf_meta_box_times']))
update_post_meta($post_id, 'golf_meta_box_times', wp_kses($_POST['golf_meta_box_times'], $allowed));
if(isset($_POST['golf_meta_box_prices']))
update_post_meta($post_id, 'golf_meta_box_prices', wp_kses($_POST['golf_meta_box_prices'], $allowed));
}
?>
如果任何人有一个线索,如何使这个拯救这将是一个很大的帮助!
我也有问题使数据显示 - 但我只能假设,它实际上节省哈哈!
干杯
我刚做了一个快速测试,它甚至显示了页面上的框中的内容,它似乎并没有保存在管理端的东西,textarea框发送数据,显示在前端,但不保存到管理端 – jamie
刚刚意识到它是什么... 我把数据输出放在textarea的值中,令人震惊的错误! – jamie
那么,解决方案是什么? – unifiedac