我在我的“创建新帖子”页面中添加了一个自定义元框,用于特定帖子类别的高级信息。
现在我认识到,如果我保存帖子,它会在db中写入2个条目,其中包含2个post\\u id。
add_action( \'add_meta_boxes\', \'my-plugin_add_custom_box\' );
add_action( \'save_post\', \'my-plugin_save_postdata\' );
my-plugin
function my-plugin_add_custom_box() {
add_meta_box(
\'my-plugin_sectionid\',
__( \'my-plugin\', \'my-plugin_textdomain\' ),
\'my-plugin_inner_custom_box\',
\'post\'
);
}
/* When the post is saved, saves our custom data */
function my-plugin_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST[\'my-plugin_noncename\'], plugin_basename( __FILE__ ) ) )
return;
// Check permissions
if ( \'page\' == $_POST[\'post_type\'] ) //is this the correct post_type?
{
if ( !current_user_can( \'edit_page\', $post_id ) )
return;
}
else
{
if ( !current_user_can( \'edit_post\', $post_id ) )
return;
}
// OK, we\'re authenticated: we need to find and save the data
//$mydata = $_REQUEST[\'sports\'];
print($post_id); //prints two post ids e.g. 831 & 832
//print($mydata); //prints two times content of $mydata
}
为什么表中有两条记录
wp_posts
是否已创建?当我更新帖子时,会创建一条新记录
post_name
post\\u id-revision(843修订版)。创建一种新的帖子类型,比如体育,对此类帖子有什么好处?我的高级信息,如
$_REQUEST[\'sports\'];
计划存储在一个单独的数据库中,并参考wp\\U POST。
提前感谢(&A);BR,
麦贝克