Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // META BOX DESCRIZIONE BAGNO
- add_action( 'add_meta_boxes', 'descbagno_select_box' );
- function descbagno_select_box() {
- add_meta_box(
- 'descbagno_select_box', // id, used as the html id att
- __( 'descrizione bagno' ), // meta box title
- 'descbagno_select_cb', // callback function, spits out the content
- 'post', // post type or page. This adds to posts only
- 'side', // context, where on the screen
- );
- }
- function descbagno_select_cb( $post ) {
- global $wpdb;
- $value = get_post_meta($post->ID, 'descbagno', true);
- $descbagni = array(
- __('bathroom with shower','sacconicase') => 'bagno con doccia',
- __('bathrooms with shower','sacconicase') => 'bagni con doccia',
- __('bathrooms','sacconicase') => 'bagni',
- __('bathrooms: one with shower and the other with bath','sacconicase') => 'bagni: uno con doccia e l\'altro con vasca',
- );
- echo '<select name="descbagno">';
- echo '<option value=""' . ((($value == '') || !isset($descbagni[$value])) ? ' selected="selected"' : '') . '> ----</option>';
- // output each description of bathroom as an option
- foreach ($descbagni as $id => $text) {
- echo '<option value="' . $id . '"' . (($value == $id) ? ' selected="selected"' : '') . '">' . $text. '</option>';
- }
- echo '</select>';
- }
- add_action( 'save_post', 'save_metadata_descbagno');
- function save_metadata_descbagno($postid)
- {
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
- if ( !current_user_can( 'edit_page', $postid ) ) return false;
- if( empty($postid) ) return false;
- if ( is_null($_REQUEST["descbagno"]) ) {
- delete_post_meta($postid, 'descbagno');
- } else {
- update_post_meta($postid, 'descbagno', $_REQUEST['descbagno']);
- }
- }
- // END META BOX DESCRIZIONE BAGNO
Advertisement
Add Comment
Please, Sign In to add comment