title: How to get and update single/multiple Custom Fields in post.php page?
body: <p>I made simple form where I can add and update Custom fields in WordPress <code>post.php</code> page.</p>
  
  <p><strong>The working code I used</strong></p>
  
  <p>I added this code in the end of my themes <strong>function.php</strong> :</p>
  
  <pre><code>define('MY_WORDPRESS_FOLDER',$_SERVER['DOCUMENT_ROOT']);
  define('MY_THEME_FOLDER',str_replace('\\','/',dirname(__FILE__)));
  define('MY_THEME_PATH','/' . substr(MY_THEME_FOLDER,stripos(MY_THEME_FOLDER,'wp-content')));
  
  add_action('admin_init','my_meta_init');
  
  function my_meta_init()
  {
      // review the function reference for parameter details
      // http://codex.wordpress.org/Function_Reference/wp_enqueue_script
      // http://codex.wordpress.org/Function_Reference/wp_enqueue_style
  
      //wp_enqueue_script('my_meta_js', MY_THEME_PATH . '/custom/meta.js', array('jquery'));
      wp_enqueue_style('my_meta_css', MY_THEME_PATH . '/custom/meta.css');
  
      // review the function reference for parameter details
      // http://codex.wordpress.org/Function_Reference/add_meta_box
  
      foreach (array('post','page') as $type) 
      {
          add_meta_box('my_all_meta', 'My Custom Meta Box', 'my_meta_setup', $type, 'normal', 'high');
      }
  
      add_action('save_post','my_meta_save');
  }
  
  function my_meta_setup()
  {
      global $post;
  
      // using an underscore, prevents the meta variable
      // from showing up in the custom fields section
      $meta = get_post_meta($post-&gt;ID,'_my_meta',TRUE);
  
      // instead of writing HTML here, lets do an include
      include(MY_THEME_FOLDER . '/custom/meta.php');
  
      // create a custom nonce for submit verification later
      echo '&lt;input type="hidden" name="my_meta_noncename" value="' . wp_create_nonce(__FILE__) . '" /&gt;';
  }
  
  function my_meta_save($post_id) 
  {
      // authentication checks
  
      // make sure data came from our meta box
      if (!wp_verify_nonce($_POST['my_meta_noncename'],__FILE__)) return $post_id;
  
      // check user permissions
      if ($_POST['post_type'] == 'page') 
      {
          if (!current_user_can('edit_page', $post_id)) return $post_id;
      }
      else 
      {
          if (!current_user_can('edit_post', $post_id)) return $post_id;
      }
  
      // authentication passed, save data
  
      // var types
      // single: _my_meta[var]
      // array: _my_meta[var][]
      // grouped array: _my_meta[var_group][0][var_1], _my_meta[var_group][0][var_2]
  
      $current_data = get_post_meta($post_id, '_my_meta', TRUE);  
  
      $new_data = $_POST['_my_meta'];
  
      my_meta_clean($new_data);
  
      if ($current_data) 
      {
          if (is_null($new_data)) delete_post_meta($post_id,'_my_meta');
          else update_post_meta($post_id,'_my_meta',$new_data);
      }
      elseif (!is_null($new_data))
      {
          add_post_meta($post_id,'_my_meta',$new_data,TRUE);
      }
  
      return $post_id;
  }
  
  function my_meta_clean(&amp;$arr)
  {
      if (is_array($arr))
      {
          foreach ($arr as $i =&gt; $v)
          {
              if (is_array($arr[$i])) 
              {
                  my_meta_clean($arr[$i]);
  
                  if (!count($arr[$i])) 
                  {
                      unset($arr[$i]);
                  }
              }
              else 
              {
                  if (trim($arr[$i]) == '') 
                  {
                      unset($arr[$i]);
                  }
              }
          }
  
          if (!count($arr)) 
          {
              $arr = NULL;
          }
      }
  }
  </code></pre>
  
  <p>Then I created a folder named "<strong>custom</strong>" inside my themes folder and saved this 2 files in there:  meta.php and meta.css</p>
  
  <p><strong>meta.php</strong> looks like:</p>
  
  <pre><code>&lt;div class="my_meta_control"&gt;
  
      &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras orci lorem, bibendum in pharetra ac, luctus ut mauris. Phasellus dapibus elit et justo malesuada eget &lt;code&gt;functions.php&lt;/code&gt;.&lt;/p&gt;
  
      &lt;label&gt;Name&lt;/label&gt;
  
      &lt;p&gt;
          &lt;input type="text" name="_my_meta[link]" value="&lt;?php if(!empty($meta['link'])) echo $meta['link']; ?&gt;"/&gt;
          &lt;span&gt;Enter in a name&lt;/span&gt;
      &lt;/p&gt;
  
      &lt;label&gt;Description &lt;span&gt;(optional)&lt;/span&gt;&lt;/label&gt;
  
      &lt;p&gt;
          &lt;textarea name="_my_meta[description]" rows="3"&gt;&lt;?php if(!empty($meta['description'])) echo $meta['description']; ?&gt;&lt;/textarea&gt;
          &lt;span&gt;Enter in a description&lt;/span&gt;
      &lt;/p&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>meta.css</strong> looks like :</p>
  
  <pre><code>.my_meta_control .description { display:none; }
  
  .my_meta_control label { display:block; font-weight:bold; margin:6px; margin-bottom:0; margin-top:12px; }
  
  .my_meta_control label span { display:inline; font-weight:normal; }
  
  .my_meta_control span { color:#999; display:block; }
  
  .my_meta_control textarea, .my_meta_control input[type='text'] { margin-bottom:3px; width:99%; }
  
  .my_meta_control h4 { color:#999; font-size:1em; margin:15px 6px; text-transform:uppercase; }
  </code></pre>
  
  <p>With this code above I get this result:</p>
  
  <p><img src="https://i.stack.imgur.com/nAEiE.png" alt="enter image description here"></p>
  
  <p>Now I can add and update Name and Description Custom Fields here which works <strong>great</strong>.</p>
  
  <p><strong>Thats what I wanted BUT the problem IS:</strong></p>
  
  <p>This box will use "Name" and "Description" from: <code>_my_meta</code> and I don't want it.
  Previously I have already saved Custom Fields Values to all my published posts as: <code>phone</code>, <code>home_city</code>, <code>home_country</code>, <code>name</code> ++ </p>
  
  <p><strong>My question is:</strong>
  How can I modify this Code to work with my already saved custom fields instead of using this new <code>_my_meta</code> ? As mentioned my custom field names is: <code>phone</code>, <code>home_city</code>, <code>home_country</code>, <code>name</code> ++ </p>