我创建了一个元框,其中选择项目从另一个帖子中获取其值。 我尝试了很多更新方法但是没有用....你能帮助我吗?
这是我的方块
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']));
}
}
我也更新了wrongest更新功能....帮帮我
答案 0 :(得分:0)
if( isset( $_POST['speaker_id'] ) ) {
update_post_meta( $post_id,'speaker_id', esc_attr( $_POST['speaker_id'] ) );
}
我找到了解决方案,但它只保存了一个值而不是多个....我该怎么办?