Sacconi69

meta field INTRO

Mar 26th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. // META BOX INTRO
  2.  
  3. add_action( 'add_meta_boxes', 'intro_select_box' );
  4. function intro_select_box() {
  5. add_meta_box(
  6. 'intro_select_box', // id, used as the html id att
  7. __( 'Introduzione' ), // meta box title
  8. 'intro_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 intro_select_cb( $post ) {
  17. global $wpdb;
  18. $value = get_post_meta($post->ID, 'intro', true);
  19.  
  20.  
  21. $intros = array(
  22. __('The apartment consists of','sacconicase') => ' L\'appartamento si compone di',
  23.  
  24. __('The house comprises of','sacconicase') => 'La casa si compone di',
  25.  
  26. __('The bungalow comprises of','sacconicase') => 'Il bungalow si compone di',
  27.  
  28. __('The apartment comprises of 1 room with living area/sleeping area + 1 bathroom','sacconicase') => 'L\'appartamento si compone di un unico ambiente zona giorno/notte + 1 bagno',
  29.  
  30.  
  31. );
  32.  
  33. echo '<select name="intro">';
  34. echo '<option value=""' . ((($value == '') || !isset($intros[$value])) ? ' selected="selected"' : '') . '> ----</option>';
  35.  
  36. // output each floor as an option
  37. foreach ($intros as $id => $text) {
  38. echo '<option value="' . $id . '"' . (($value == $id) ? ' selected="selected"' : '') . '">' . $text. '</option>';
  39. }
  40. echo '</select>';
  41.  
  42.  
  43. }
  44.  
  45. add_action( 'save_post', 'save_metadata_intro');
  46.  
  47. function save_metadata_intro($postid)
  48. {
  49. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
  50. if ( !current_user_can( 'edit_page', $postid ) ) return false;
  51. if( empty($postid) ) return false;
  52.  
  53.  
  54. if ( is_null($_REQUEST["intro"]) ) {
  55. delete_post_meta($postid, 'intro');
  56. } else {
  57. update_post_meta($postid, 'intro', $_REQUEST['intro']);
  58. }
  59.  
  60. }
  61. // END INTRO
  62.  
Advertisement
Add Comment
Please, Sign In to add comment