Php wordpress元框混淆
我的问题是关于Php wordpress元框混淆,php,mysql,wordpress,Php,Mysql,Wordpress,我的问题是关于save($posted)功能。这里有一个参数$postID,它在保存为id的函数中使用。我看到这个$postID有一个空值。$postID的实际post id是如何工作的 This is the simple meta-box code /* simple meta box */ /* creating field */ add_action('admin_menu', 'my_post_options_box'); function my_post_options_bo
save($posted)
功能。这里有一个参数$postID
,它在保存为id的函数中使用。我看到这个$postID
有一个空值。$postID
的实际post id是如何工作的
This is the simple meta-box code
/* simple meta box */
/* creating field */
add_action('admin_menu', 'my_post_options_box');
function my_post_options_box() {
if ( function_exists('add_meta_box') ) {
add_meta_box('post_header', 'Asif, save me!', 'testfield', 'post', 'normal', 'low');
}
}
function testfield(){
global $post;
?>
<input type="text" name="Asif" id="Asif" value="<?php echo get_post_meta($post->ID, 'Sumon', true); ?>">
<?php
}
/* end of creating field */
/* storing field after pressing save button */
add_action('save_post', 'save');
function save($postID){
if (!defined('DOING_AUTOSAVE') && !DOING_AUTOSAVE) {
return $postID;
}
else
{
if($parent_id = wp_is_post_revision($postID))
{
$postID = $parent_id;
}
if ($_POST['Asif'])
{
update_custom_meta($postID, $_POST['Asif'], 'Sumon');
}
}
}
// saving in postmeta table
function update_custom_meta($postID, $newvalue, $field_name){
if(!get_post_meta($postID, $field_name)){
// create field
add_post_meta($postID, $field_name, $newvalue);
}
else{
//update field
update_post_meta($postID, $field_name, $newvalue);
}
}
这是简单的元框代码
/*简单元盒*/
/*创建字段*/
添加操作(“管理菜单”、“我的帖子选项”框);
函数my_post_options_box(){
如果(函数_存在('add_meta_box')){
添加元框('post_header','Asif,save me!','testfield','post','normal','low');
}
}
函数testfield(){
全球$员额;
?>
你用错动作钩了
不要使用add\u操作(“管理”菜单、“我的帖子”选项框);
使用add_操作('add_meta_box','my_post_options_box');
您可以查看以获取详细概述
有些问题/答案是你可以研究的
在保存邮件时
操作save\u post
自动将post ID传递给回调函数。您可以在回调函数中使用它
有些人已经回答了问题
参考
你把这个函数放在哪里了?上面的代码放在我的wordpress主题的function.php中。代码工作正常。但是我不明白save函数的参数是如何工作的?
add_action('add_meta_boxes', 'my_post_options_box');
function my_post_options_box() {
if ( function_exists('add_meta_box') ) {
add_meta_box('post_header', 'Asif, save me!', 'testfield', 'post', 'normal', 'low');
}
}