I already have a meta box in the edit post that has a select list with custom taxonomies. But after i save the post the select list returns it value to none, so i don't know how to save the selected value. Can't solve this as i can't figure other codes that don't deal with this one.
Here's my php that creates the metabox and the select list:
<?
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>
And here's the one that should save the value:
<?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' ] );
}
}
?>