Sacconi69

posto auto field

Mar 11th, 2024
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. // META BOX POSTO AUTO
  2.  
  3. add_action( 'add_meta_boxes', 'postoauto_select_box' );
  4. function postoauto_select_box() {
  5. add_meta_box(
  6. 'postoauto_select_box', // id, used as the html id att
  7. __( 'descrizione posto auto' ), // meta box title
  8. 'postoauto_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 postoauto_select_cb( $post ) {
  17. global $wpdb;
  18. $value = get_post_meta($post->ID, 'postoauto', true);
  19.  
  20.  
  21. $postiauto = array(
  22.  
  23. __('1 parking lot','sacconicase') => '1 posto auto',
  24.  
  25. __('1 parking space in the garage (normal car, no SUVs and minibuses) or sometimes outside','sacconicase') => ' 1 posto auto nel garage (per auto utilitarie, no Suv e minibus) o talvolta esterno ',
  26.  
  27. __('1 parking lot on request','sacconicase') => '1 posto auto su richiesta',
  28.  
  29. __('2 parking lots','sacconicase') => '2 posti auto',
  30.  
  31. __('garage for 2 cars','sacconicase') => 'garage per 2 auto',
  32.  
  33. __('garage on demand','sacconicase') => 'garage su richiesta',
  34.  
  35. __('garage','sacconicase') => 'garage',
  36.  
  37. __('parking area','sacconicase') => 'parcheggio',
  38.  
  39. __('private parking','sacconicase') => 'parcheggio privato',
  40.  
  41. __('public outdoor parking','sacconicase') => 'parcheggio pubblico',
  42.  
  43. __('private parking places outside','sacconicase') => 'posti auto privati esterni',
  44.  
  45. __('parking spaces reserved for the condominium\, parking space not guaranteed','sacconicase') => 'posti auto riservati al condominio, posto auto non garantito',
  46.  
  47. __('parking places','sacconicase') => 'posti auto',
  48.  
  49. __('parking place 50 m. away','sacconicase') => 'posto auto a 50 m.',
  50.  
  51. __('closed parking place','sacconicase') => 'posto auto chiuso',
  52.  
  53. __('parking in the yard','sacconicase') => 'posto auto in cortile',
  54.  
  55. __('no parking place','sacconicase') => 'posto auto non disponibile',
  56.  
  57.  
  58. );
  59.  
  60.  
  61. echo '<select name="postoauto">';
  62. echo '<option value=""' . ((($value == '') || !isset($postiauto[$value])) ? ' selected="selected"' : '') . '> ----</option>';
  63.  
  64. // output each description of the parking place as an option
  65. foreach ($postiauto as $id => $text) {
  66. echo '<option value="' . $id . '"' . (($value == $id) ? ' selected="selected"' : '') . '">' . $text. '</option>';
  67. }
  68. echo '</select>';
  69.  
  70.  
  71. }
  72.  
  73. add_action( 'save_post', 'save_metadata_postoauto');
  74.  
  75. function save_metadata_postoauto($postid)
  76. {
  77. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
  78. if ( !current_user_can( 'edit_page', $postid ) ) return false;
  79. if( empty($postid) ) return false;
  80.  
  81.  
  82. if ( is_null($_REQUEST["postoauto"]) ) {
  83. delete_post_meta($postid, 'postoauto');
  84. } else {
  85. update_post_meta($postid, 'postoauto', $_REQUEST['postoauto']);
  86. }
  87.  
  88. }
  89. // END META BOX POSTO AUTO
  90.  
Advertisement
Add Comment
Please, Sign In to add comment