我在编辑帖子中已经有了一个元框,它有一个带有自定义分类法的选择列表。但在我保存帖子后,选择列表会将其值返回为none,so i don\'t know how to save the selected value. 无法解决此问题,因为我无法找到其他不处理此问题的代码。
下面是我的php,它创建了metabox和select列表:
<?
function prfx_custom_meta() {
add_meta_box( \'prfx_meta\', __( \'Reproductor 1\', \'prfx-textdomain\' ), \'prfx_meta_callback\', \'post\' );
}
add_action( \'add_meta_boxes\', \'prfx_custom_meta\' );
function prfx_meta_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), \'prfx_nonce\' );
$prfx_stored_meta = get_post_meta( $post->ID );
?>
<p>
<label for="Netu" class="prfx-row-title"><?php _e( \'Netu\', \'prfx-textdomain\' )?></label>
<select name="Netu" id="Netu">
<option value="Ninguno" <?php if ( isset ( $prfx_stored_meta[\'Ninguno\'] ) ) selected( $prfx_stored_meta[\'Ninguno\'][0], \'Ninguno\' ); ?>><?php _e( \'Netu\', \'prfx-textdomain\' )?></option>\';
<option value="Netu" <?php if ( isset ( $prfx_stored_meta[\'Netu-cast\'] ) ) selected( $prfx_stored_meta[\'Netu-cast\'][0], \'Netu Castellano\' ); ?>><?php _e( \'Netu
Castellano\', \'prfx-textdomain\' )?></option>\';
<option value="Netu-vose" <?php if ( isset ( $prfx_stored_meta[\'Netu-vose\'] ) ) selected( $prfx_stored_meta[\'Netu-vose\'][0], \'Netu Inglés Subtitulado\' ); ?>><?php _e(
\'Netu Inglés Subtitulado\', \'prfx-textdomain\' )?></option>\';
<option value="Netu-latino" <?php if ( isset ( $prfx_stored_meta[\'Netu-latino\'] ) ) selected( $prfx_stored_meta[\'Netu-latino\'][0], \'Netu Latino\' ); ?>><?php _e( \'Netu Latino\', \'prfx-textdomain\' )?></option>\';
</select>
</p>
下面是一个应该保存价值的方法:
<?php }
function prfx_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ \'prfx_nonce\' ] ) && wp_verify_nonce( $_POST[ \'prfx_nonce\' ], basename( __FILE__ ) ) ) ? \'true\' : \'false\';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
add_action( \'save_post\', \'prfx_meta_save\' );
if( isset( $_POST[ \'Netu\' ] ) ) {
update_post_meta( $post_id, \'Netu\', $_POST[ \'Netu\' ] );
}
if( isset( $_POST[ \'Ninguno\' ] ) ) {
update_post_meta( $post_id, \'Ninguno\', $_POST[ \'Ninguno\' ] );
}
if( isset( $_POST[ \'Netu-cast\' ] ) ) {
update_post_meta( $post_id, \'Netu-cast\', $_POST[ \'Netu-cast\' ] );
}
if( isset( $_POST[ \'Netu-vose\' ] ) ) {
update_post_meta( $post_id, \'Netu-vose\', $_POST[ \'Netu-vose\' ] );
}
if( isset( $_POST[ \'Netu-latino\' ] ) ) {
update_post_meta( $post_id, \'Netu-latino\', $_POST[ \'Netu-latino\' ] );
}
}
?>