Sacconi69

META BOX DESCRIZIONE BAGNO

Mar 11th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. // META BOX DESCRIZIONE BAGNO
  2.  
  3. add_action( 'add_meta_boxes', 'descbagno_select_box' );
  4. function descbagno_select_box() {
  5. add_meta_box(
  6. 'descbagno_select_box', // id, used as the html id att
  7. __( 'descrizione bagno' ), // meta box title
  8. 'descbagno_select_cb', // callback function, spits out the content
  9. 'post', // post type or page. This adds to posts only
  10. 'side', // context, where on the screen
  11.  
  12. );
  13.  
  14. }
  15.  
  16. function descbagno_select_cb( $post ) {
  17. global $wpdb;
  18. $value = get_post_meta($post->ID, 'descbagno', true);
  19.  
  20.  
  21. $descbagni = array(
  22.  
  23. __('bathroom with shower','sacconicase') => 'bagno con doccia',
  24. __('bathrooms with shower','sacconicase') => 'bagni con doccia',
  25. __('bathrooms','sacconicase') => 'bagni',
  26. __('bathrooms: one with shower and the other with bath','sacconicase') => 'bagni: uno con doccia e l\'altro con vasca',
  27.  
  28. );
  29.  
  30.  
  31. echo '<select name="descbagno">';
  32. echo '<option value=""' . ((($value == '') || !isset($descbagni[$value])) ? ' selected="selected"' : '') . '> ----</option>';
  33.  
  34. // output each description of bathroom as an option
  35. foreach ($descbagni as $id => $text) {
  36. echo '<option value="' . $id . '"' . (($value == $id) ? ' selected="selected"' : '') . '">' . $text. '</option>';
  37. }
  38. echo '</select>';
  39.  
  40.  
  41. }
  42.  
  43. add_action( 'save_post', 'save_metadata_descbagno');
  44.  
  45. function save_metadata_descbagno($postid)
  46. {
  47. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
  48. if ( !current_user_can( 'edit_page', $postid ) ) return false;
  49. if( empty($postid) ) return false;
  50.  
  51.  
  52. if ( is_null($_REQUEST["descbagno"]) ) {
  53. delete_post_meta($postid, 'descbagno');
  54. } else {
  55. update_post_meta($postid, 'descbagno', $_REQUEST['descbagno']);
  56. }
  57.  
  58. }
  59. // END META BOX DESCRIZIONE BAGNO
  60.  
Advertisement
Add Comment
Please, Sign In to add comment