In the functions.php of my WordPress theme I am adding a Dropdown list / Check list that is shown in the edit post as meta box. It has four options. “Ninguno, Netu-cast, Netu-vose, Netu-latino”
<?
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>
<span class="prfx-row-title"><?php _e( 'Servidor y lenguaje', 'prfx-textdomain' )?> </span>
<div class="prfx-row-content">
<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>
</div>
</p>
This is the code that should save this check list after clicking “Save post”:
<?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[ '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' ] );
}
}
?>
But it is not saving the clicked data of the checklist.
What is wrong?
After :
You just need: