我在帖子上有一个简单的复选框,可以在滑块中显示帖子,一切正常。但我想切换并只在滑块中添加页面,但下面的代码并没有更新页面的wp\\U Posteta表,只更新帖子。你能告诉我我做错了什么吗
function damad_add_post_metabox() {
$screens = array( \'post\', \'page\');
foreach ( $screens as $screen ) {
add_meta_box(
\'damad_post_meta_id\',
__( \'Options\', \'damad\' ),
\'damad_inner_custom_box\',
$screen
);
}
}
add_action( \'add_meta_boxes\', \'damad_add_post_metabox\' );
function damad_inner_custom_box( $post ) {
wp_nonce_field( \'damad_inner_custom_box\', \'damad_inner_custom_box_nonce\' );
$homepage = get_post_meta( $post->ID, \'_post_featured\', true);
echo \'<label for="post-featured">\';
_e("Include in homepage slider", \'damad\');
echo "</label>";
echo \'<input type="checkbox" id="post-featured" name="post-featured" value="post-featured"\';
if ( \'post-featured\' == $homepage ) {
echo \'checked="checked"\';
}
echo \'/>\';
}
function damad_save_postdata( $post_id ) {
if ( ! isset( $_POST[\'damad_inner_custom_box_nonce\'] ) )
return $post_id;
$nonce = $_POST[\'damad_inner_custom_box_nonce\'];
if ( ! wp_verify_nonce( $nonce, \'damad_inner_custom_box\' ) )
return $post_id;
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return $post_id;
if ( \'page\' == $_POST[\'post_type\'] ) {
if ( ! current_user_can( \'edit_page\', $post_id ) )
return $post_id;
} else {
if ( ! current_user_can( \'edit_post\', $post_id ) )
return $post_id;
}
$featureddata = $_POST[\'post-featured\'];
update_post_meta( $post_id, \'_post_featured\', $featureddata );
}
add_action( \'save_post\', \'damad_save_postdata\' );