我为自定义元帖子编写了代码。元帖子是显示在自定义帖子下方的复选框。但是当我试图保存它。它不保存并留下复选框blank.i不知道为什么它不保存? 使用另一个自定义帖子复选框。
add_action( 'add_meta_boxes', 'cd_meta_box_add_alert' );
function cd_meta_box_add_alert()
{
add_meta_box( 'my-meta-box-id-2', 'Select People for blog',
'cd_meta_box_cb_alert', 'alert' , 'normal', 'high' );
}
function cd_meta_box_cb_alert()
{
// $post is already set, and contains an object: the WordPress post
global $alert;
$valuesalert = get_post_custom( $post->ID );
// We'll use this nonce field later on when saving.
wp_nonce_field( 'alert_my_meta_box_nonce', 'alert_meta_box_nonce' );
$checkalert = isset( $valuesalert['people_to_alert'] ) ? esc_attr($valuesalert['people_to_alert'][0] ) : '';
$people_array_alert = unserialize($valuesalert['people_to_alert'][0]);
$args = array(
'post_type' => 'lowenbaumpeople',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
);
$queryalert = new WP_Query( $args );
while ( $queryalert->have_posts() ) : $queryalert->the_post();
if ( !empty($people_array_alert) && is_array($people_array_alert) ) {
$checkalert = (in_array($post->ID, $people_array_alert)) ? 'on' : '';
}
<input type="checkbox" value="<?php echo $post->ID; ?>" name="people_to_blog[]" <?php checked( $checkalert, 'on' ); ?> />
<label for="people_to_blog"><?php the_title();?></label>
add_action( 'save_post', 'cd_meta_box_save_alert' );
function cd_meta_box_save_alert( $post_id )
{ global $post;
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['alert_meta_box_nonce'] ) || !wp_verify_nonce($_POST['alert_meta_box_nonce'], 'alert_my_meta_box_nonce' ) ) return;
if( !current_user_can( 'edit_post' ) ) return;
update_post_meta( $post_id, 'people_to_alert', $_POST['people_to_alert'] );
}
我打开了调试模式并发现了这些错误
[13-Sep-2015 11:09:59 UTC] PHP注意:未定义的偏移量:0/1199行/home/cdrossen6800/public_html/lowenbaumlaw/wp-includes/capabilities.php中的0 [13-Sep-2015 11:09:59 UTC] PHP注意:未定义的索引:811行/home/cdrossen6800/public_html/lowenbaumlaw/wp-content/themes/lowenbaum/functions.php中的people_to_alert [13-Sep-2015 11:10:00 UTC] PHP注意:第957行/home/cdrossen6800/public_html/lowenbaumlaw/wp-includes/formatting.php中的数组到字符串转换