Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

add_action('add_meta_boxes','program_detail');
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>
  </select> 

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




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
2  
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

 
discard

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

Browse other questions tagged or ask your own question.