Sacconi69

META BOX PIANO

Feb 25th, 2024
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. // META BOX PIANO
  2.  
  3. add_action( 'add_meta_boxes', 'piano_select_box' );
  4. function piano_select_box() {
  5. add_meta_box(
  6. 'piano_select_box', // id, used as the html id att
  7. __( 'Piano' ), // meta box title
  8. 'piano_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. 'low' // priority, where should this go in the context
  12. );
  13.  
  14. }
  15.  
  16. function piano_select_cb( $post ) {
  17. global $wpdb;
  18. $value = get_post_meta($post->ID, 'piano', true);
  19.  
  20.  
  21. $piani = array(
  22. __(' ground floor, ','sacconicase') => ' piano terra ', __(' upper ground floor, ','sacconicase') => ' piano rialzato ',
  23. __(' ground floor or 1st floor, ','sacconicase') => ' piano terra o primo piano',
  24. __(' 1st floor, ','sacconicase') => ' 1°piano ',
  25. __(' 2nd floor, ','sacconicase') => ' 2°piano ',
  26. __(' 2nd or 3rd floor, ','sacconicase') => ' 2°o 3° piano ',
  27. __(' 3rd floor, ','sacconicase') => ' 3°piano ',
  28. __(' 4th floor, ','sacconicase') => ' 4°piano ',
  29. __(' 5th floor, ','sacconicase') => ' 5°piano ',
  30. __(' 6th floor, ','sacconicase') => ' 6°piano ',
  31. __(' 7th floor, ','sacconicase') => ' 7°piano ',
  32. __(' 8th floor, ','sacconicase') => ' 8°piano ',
  33. __(' 9th floor, ','sacconicase') => ' 9°piano ',
  34. __(' 10th floor, ','sacconicase') => ' 10°piano ',
  35. __(' 11th floor, ','sacconicase') => ' 11°piano ',
  36. __(' 12th floor, ','sacconicase') => ' 12°piano ',
  37. __(' 13th floor, ','sacconicase') => ' 13°piano ',
  38. __(' 14th floor, ','sacconicase') => ' 14°piano ',
  39. __(' 15th floor, ','sacconicase') => ' 15°piano ',
  40. __(' roof-floor, ','sacconicase') => ' mansarda',
  41. );
  42.  
  43. echo '<select name="piano">';
  44. echo '<option value=""' . ((($value == '') || !isset($piani[$value])) ? ' selected="selected"' : '') . '> ----</option>';
  45.  
  46. // output each floor as an option
  47. foreach ($piani as $id => $text) {
  48. echo '<option value="' . $id . '"' . (($value == $id) ? ' selected="selected"' : '') . '">' . $text. '</option>';
  49. }
  50. echo '</select>';
  51.  
  52. echo '</span></div>';
  53. }
  54.  
  55. add_action( 'save_post', 'save_metadata');
  56.  
  57. function save_metadata($postid)
  58. {
  59. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
  60. if ( !current_user_can( 'edit_page', $postid ) ) return false;
  61. if( empty($postid) ) return false;
  62.  
  63.  
  64. if ( is_null($_REQUEST["piano"]) ) {
  65. delete_post_meta($postid, 'piano');
  66. } else {
  67. update_post_meta($postid, 'piano', $_REQUEST['piano']);
  68. }
  69.  
  70. }
  71. // END FLOOR OF THE APARTMENT
  72.  
Advertisement
Add Comment
Please, Sign In to add comment