0

我创建了一个带有选择项的元框,它从另一个帖子中获取其值。我尝试了许多更新方法,但都不起作用....你能帮帮我吗?

这是我的盒子

add_action("add_meta_boxes", "palinsesto_box");

function palinsesto_box() {
add_meta_box("palinsesto-meta", "Speakers",   "palinsesto_manager_meta_options", "palinsesto",   "side");}

function palinsesto_manager_meta_options($post)
{
wp_nonce_field( 'radio_schedule', 'schedule_noncename' );
echo '<label for="speaker_id">';
_e("Speaker", 'speaker_id' );
echo '</label> ';
$args = array( 'post_type' => 'speaker');
$loop = new WP_Query( $args );
echo '<select name="speaker_id" id="speaker_id" multiple="multiple">';
foreach($loop->posts as $dj):
    if($dj->ID == get_post_meta( $post->ID, 'speaker_id', true ))
    {
        $select = 'selected';
    }else{
    $select = '';
}
echo '<option value="'.$dj->ID.'" '.$select.'>'.$dj->post_title.'</option>';
endforeach;
echo '</select>';
echo '<p>Tieni premuto CTRL per selezionare più speakers</p>';
}

add_action('save_post', 'save_palinsesto_manager_meta_options');
function save_palinsesto_manager_meta_options($post_id)
{global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
    //if you remove this the sky will fall on your head.
    return;
}else{
    update_post_meta($post->ID, 'speaker_id', implode( ',', $_POST['speaker_id']));
}
}

我也更新了最错误的更新功能....帮帮我

4

1 回答 1

0
if( isset( $_POST['speaker_id'] ) ) {  
    update_post_meta( $post_id,'speaker_id', esc_attr( $_POST['speaker_id'] ) );  
}

我找到了解决方案,但它只保存一个值而不是多个值....我该怎么办?

于 2013-10-27T15:02:43.120 回答