WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made this metabox with an input item and two select items(a dropdown and a checkbox). When i write something in the input item or i select something it disappear when i update the post. Another bug: the permalink take the name from the selected value of another metabox and not from the title...how can i fix that?

This is my code, i hope you can help me.

function program_detail(){
add_meta_box('orario_id', 'Dettagli Programma', 'program_options','palinsesto', 'normal');

function program_options($post){

$values = get_post_custom( $post->ID );
$text = isset( $values['orario'] ) ? esc_attr( $values['orario'][0] ) : ”;
$selected = isset( $values['giorno'] ) ? esc_attr( $values['giorno'][0] ) : ”;
$check = isset( $values['replica'] ) ? esc_attr( $values['replica'][0] ) : ”;

?> <p><label for="giorno"><b>Giorno:</b></label>
  <select name="giorno" id="giorno">
    <option value="lunedì"<?php selected( $selected, 'lunedì' ); ?>>Lunedì</option>
    <option value="martedì"<?php selected( $selected, 'martedì' ); ?>>Martedì</option>
    <option value="mercoledì"<?php selected( $selected, 'mercoldì' ); ?>>Mercoledì</option>
    <option value="giovedì"<?php selected( $selected, 'giovedì' ); ?>>Giovedì</option>
    <option value="venerdì"<?php selected( $selected, 'venerdì' ); ?>>Venerdì</option>
    <option value="sabato"<?php selected( $selected, 'sabato' ); ?>>Sabato</option>
    <option value="domenica"<?php selected( $selected, 'domenica' ); ?>>Domenica</option>

    <label for="orario"><b>Ora (formato hh:mm):</b></label>  
    <input type="text" name="orario" id="orario" value="<?php echo $text; ?>" />  
<p>Selezionare se è la replica</p>
<input type="checkbox" id="replica" name="replica" <?php checked( $check, 'on' ); ?> />  
<label for="replica"><b>Replica</b></label>  

add_action( 'save_post', 'program_options_save' );  
function program_options_save( $post_id ){
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;

if( isset( $_POST['orario'] ) )  
update_post_meta( $post_id, 'orario', wp_kses( $_POST['orario'], $allowed )  );  

if( isset( $_POST['giorno'] ) )  
update_post_meta( $post_id, 'giorno', esc_attr( $_POST['giorno'] ) );  

// This is purely my personal preference for saving check-boxes  
$chk = isset( $_POST['replica'] ) && $_POST['replica'] ? 'on' : 'off';  
update_post_meta( $post_id, 'replica', $chk ); 
share|improve this question
your ternary operators at the top of the program_options have curly quotes instead of proper single quotes ''. always develop with debugging enabled. – Milo Nov 8 '13 at 22:07
i have changed the quotes but the data always disappear when i upload the post – zen Nov 9 '13 at 13:28
"Mercoledì" is misspelled inside the selected arguments. Otherwise, the code works for me (with corrected quotes). I can't duplicate the problem. – s_ha_dum Nov 9 '13 at 17:10
i don't know why it always disappear – zen Nov 10 '13 at 9:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.