我为页面创建了一个元框,请参见以下代码:
add_action(\'add_meta_boxes\', \'add_metaboxes\');
function add_metaboxes() {
add_meta_box(
\'wpt_slider_meta\',
\'Add Slider Image\',
\'wpt_slider_meta\',
\'slider\',
\'normal\',
\'default\'
);
}
function wpt_slider_meta() {
global $post;
wp_nonce_field(plugins_url(__FILE__), \'meta_slider_noncename\');
$values = get_post_meta($post->ID, \'_meta-slider_img\', true);
// Some html and scripts to upload image.
}
add_action( \'save_post\', \'save_slider_img\' );
function save_slider_img( $post_id ) {
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if ( \'slider\' == $_POST[\'post_type\'] ) {
if ( !current_user_can( \'edit_page\', $post_id ) )
return;
} else {
if ( !current_user_can( \'edit_post\', $post_id ) )
return;
}
if(wp_verify_nonce($_POST[\'meta_slider_noncename\'], plugins_url(__FILE__)) )
{
$images = $_POST[\'meta-slider_img\'];
update_post_meta( $post_id, \'_meta-slider_img\', $images );
}
}
当我点击添加新页面时,我收到了两条警告;除此之外,所有代码都可以正常工作。
Notice: Undefined index: post_type in /var/www/html/transport/wp-content/themes/transport/functions.php on line 192
Notice: Undefined index: meta_slider_noncename in /var/www/html/transport/wp-content/themes/transport/functions.php on line 200
有人能帮忙吗?