我为metaboxes和保存信息创建了这个函数,但我不能保存信息并将其显示在字段中。
我的代码:
function reaction_buttons_meta2()
{
global $post;
$reaction_buttons_off2 = false;
if ( get_post_meta($post->ID, '_reaction_buttons_off2', true) ) {
$reaction_buttons_off = true;
}
update_post_meta($post->ID, 'reaction_buttons_off2', $_POST['reaction_buttons_off2']);
$meta=get_post_meta($post->ID, $field['reaction_buttons_off2'], true);
?>
<input type="text" id="reaction_buttons_off2" name="reaction_buttons_off2" value="<?php echo $meta[reaction_buttons_off2][0]; ?>">
<?php
}
function reaction_buttons_meta_box2()
{
add_meta_box('reaction_buttons2','Reaction Buttons','reaction_buttons_meta2','post','side');
add_meta_box('reaction_buttons2','Reaction Buttons','reaction_buttons_meta2','page','side');
}
add_action('admin_menu', 'reaction_buttons_meta_box2');我需要放置一个简单的字段来存储一个选项,然后在模板帖子中显示它。
发布于 2013-05-13 15:20:32
我自己从来没有创建过meta boxes,但看看你的代码,你所做的一切都是试图更新meta,但你需要先用add_post_meta添加它。
查看有关如何在WordPress中创建自定义帖子Meta框的this文章。
对于您的问题,请注意Saving the meta box data部分。如您所见,它们的函数使用add_post_meta、update_post_meta和delete_post_meta函数。
https://stackoverflow.com/questions/16512261
复制相似问题