meta boxes - wordpress metabox: how to divide one metabox in 2 or more -


i have code

<?php $prefix = 'wtf_'; $meta_box = array(     'id' => 'propertybox',     'title' => 'property listing details',     'page' => 'listings',     'context' => 'normal',     'priority' => 'high',     'fields' => array(             array(             'name' => 'propert id number',             'desc' => 'enter property id number, if ',             'id' => $prefix . 'pid',             'type' => 'text',             'std' => ''         ),           array(             'name' => 'bath',             'desc' => 'number of bathrooms.',             'id' => $prefix . 'bath',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'an',             'desc' => 'anul constructiei',             'id' => $prefix . 'an',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'etaj',             'desc' => 'etajul',             'id' => $prefix . 'etaj',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'balcone',             'desc' => 'numar balcoane',             'id' => $prefix . 'balcon',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'parcare',             'desc' => 'numar locuri de parcare',             'id' => $prefix . 'parcare',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'suprafata totala',             'desc' => 'suprafata totala terenului (casa/vila)',             'id' => $prefix . 'suprafatatotala',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'front stradal',             'desc' => 'suprafata front stradal',             'id' => $prefix . 'front',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'suprafata curte libera ',             'desc' => 'suprafata curte libera ',             'id' => $prefix . 'suprafatacurte',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'amprenta casei ',             'desc' => 'suprafata amprentei  ',             'id' => $prefix . 'amprenta',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'regim inaltime',             'desc' => 'regim inaltime  ',             'id' => $prefix . 'inaltime',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'certificat urbanism ',             'desc' => 'certificat urbanism',             'id' => $prefix . 'certificat',             'type' => 'text',             'std' => ''         ),                array(             'name' => 'asking price',             'desc' => 'enter actual asking price ',             'id' => $prefix . 'price',             'type' => 'text',             'std' => ''         )       ),  );   add_action('admin_menu', 'mytheme_add_box');  // add meta box function mytheme_add_box() {     global $meta_box;      add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']); }  // callback function show fields in meta box function mytheme_show_box() {     global $meta_box, $post;      // use nonce verification     echo '<input type="hidden" name="mytheme_meta_box_nonce" value="', wp_create_nonce(basename(__file__)), '" />';      echo '<table class="form-table">';      foreach ($meta_box['fields'] $field) {         // current post meta data         $meta = get_post_meta($post->id, $field['id'], true);          echo '<tr>',                 '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',                 '<td>';         switch ($field['type']) {             case 'text':                 echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',                     '<br />', $field['desc'];                 break;             case 'textarea':                 echo '<textarea class="theeditor" name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',                     '<br />', $field['desc'];                  break;             case 'select':                 echo '<select name="', $field['id'], '" id="', $field['id'], '">';                 foreach ($field['options'] $option) {                     echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';                 }                 echo '</select>',                 '<br />', $field['desc'];                 break;             case 'radio':                 foreach ($field['options'] $option) {                     echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' />', $option['name'];                 }                 break;             case 'checkbox':                 echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';                 break;         }         echo    '<td>',             '</tr>';     }      echo '</table>'; }  add_action('save_post', 'mytheme_save_data');  // save data meta box function mytheme_save_data($post_id) {     global $meta_box;      // verify nonce     if (!wp_verify_nonce($_post['mytheme_meta_box_nonce'], basename(__file__))) {         return $post_id;     }      // check autosave     if (defined('doing_autosave') && doing_autosave) {         return $post_id;     }      // check permissions     if ('page' == $_post['post_type']) {         if (!current_user_can('edit_page', $post_id)) {             return $post_id;         }     } elseif (!current_user_can('edit_post', $post_id)) {         return $post_id;     }      foreach ($meta_box['fields'] $field) {         $old = get_post_meta($post_id, $field['id'], true);         $new = $_post[$field['id']];          if ($new && $new != $old) {             update_post_meta($post_id, $field['id'], $new);         } elseif ('' == $new && $old) {             delete_post_meta($post_id, $field['id'], $old);         }     } }  ?> 

that generate in dashbord

enter image description here

and want in dashbord of wordpress have more 1 meta_box(property listings details) want mansion listing details , why not if can add more

this code came have error when try use

    <?php    $prefix = 'wtf_';  $property_fields = array(          array(             'name' => 'propert id number',             'desc' => 'enter property id number, if ',             'id'   =>   $prefix.'pid',             'type' => 'text',             'std'   => ''          ),          array(             'name' => 'bath',             'desc' => 'number of bathrooms.',             'id'   => $prefix.'bath',             'type' => 'text',             'std'  => ''          ),                array(              'name' => 'an',              'desc' => 'anul constructiei',              'id'   => $prefix.'an',              'type' => 'text',              'std'  => ''          ));  $mansion_fields = array(          array(         'name' => 'etaj',         'desc' => 'etajul',         'id' => $prefix . 'etaj',         'type' => 'text',         'std' => ''     ),            array(         'name' => 'balcone',         'desc' => 'numar balcoane',         'id' => $prefix . 'balcon',         'type' => 'text',         'std' => ''     ),            array(         'name' => 'parcare',         'desc' => 'numar locuri de parcare',         'id' => $prefix . 'parcare',         'type' => 'text',         'std' => ''     ),            array(         'name' => 'suprafata totala',         'desc' => 'suprafata totala terenului (casa/vila)',         'id' => $prefix . 'suprafatatotala',         'type' => 'text',         'std' => ''     ),            array(         'name' => 'front stradal',         'desc' => 'suprafata front stradal',         'id' => $prefix . 'front',         'type' => 'text',         'std' => ''     ),            array(         'name' => 'suprafata curte libera ',         'desc' => 'suprafata curte libera ',         'id' => $prefix . 'suprafatacurte',         'type' => 'text',         'std' => ''     ),            array(         'name' => 'amprenta casei ',         'desc' => 'suprafata amprentei  ',         'id' => $prefix . 'amprenta',         'type' => 'text',         'std' => ''     ),              array(         'name' => 'regim inaltime',         'desc' => 'regim inaltime  ',         'id' => $prefix . 'inaltime',         'type' => 'text',         'std' => ''     ),            array(         'name' => 'certificat urbanism ',         'desc' => 'certificat urbanism',         'id' => $prefix . 'certificat',         'type' => 'text',         'std' => ''     ),            array(         'name' => 'asking price',         'desc' => 'enter actual asking price ',         'id' => $prefix . 'price',         'type' => 'text',         'std' => ''     ));  add_action( 'add_meta_boxes', 'my_meta_boxes' ); function my_meta_boxes(){     //don't forget change "post" post_type want add metaboxes     add_meta_box("propertybox", "property options", "propertybox", "listings", "normal", "high");     add_meta_box("mansionbox", "mansion options", "mansionbox", "listings", "normal", "high");  }  function propertybox(){     global $prefix;     global $property_fields;    //put here fields want display inside "property options" box.     build_fieds($property_fields); }  function mansionbox(){     global $prefix;     global $mansion_fields;      build_fieds($mansion_fields); }  function build_fieds($fields){      global $post;       echo '<table class="form-table">';  foreach ($fields $field) {     // current post meta data     $meta = get_post_meta($post->id, $field['id'], true);      echo '<tr>',             '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',         '<td>';     switch ($field['type']) {         case 'text':             echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',             '<br />', $field['desc'];             break;         case 'textarea':             echo '<textarea class="theeditor" name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',             '<br />', $field['desc'];              break;         case 'select':             echo '<select name="', $field['id'], '" id="', $field['id'], '">';             foreach ($field['options'] $option) {                 echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';         }             echo '</select>',         '<br />', $field['desc'];             break;         case 'radio':             foreach ($field['options'] $option) {                 echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' />', $option['name'];         }             break;         case 'checkbox':             echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';             break;     }     echo    '<td>',         '</tr>'; }   echo '</table>'; }  add_action('save_post', 'mytheme_save_data');  // save data meta box function mytheme_save_data($post_id) {      global $mansion_fields;     global $property_fields;      // check autosave     if (defined('doing_autosave') && doing_autosave) {         return $post_id;     }      // check permissions     if ('page' == $_post['post_type']) {         if (!current_user_can('edit_page', $post_id)) {             return $post_id;         }     } elseif (!current_user_can('edit_post', $post_id)) {         return $post_id;     }      foreach ($property_fields $field) {         $old = get_post_meta($post_id, $field['id'], true);         $new = $_post[$field['id']];          if ($new && $new != $old) {             update_post_meta($post_id, $field['id'], $new);         } elseif ('' == $new && $old) {             delete_post_meta($post_id, $field['id'], $old);         }      }      foreach ($mansion_fields $field) {         $old = get_post_meta($post_id, $field['id'], true);         $new = $_post[$field['id']];         if ($new && $new != $old) {            update_post_meta($post_id, $field['id'], $new);        } elseif ('' == $new && $old) {            delete_post_meta($post_id, $field['id'], $old);        }      } }     ?> 


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -