title: create a gallery meta box with titles/captions in custom post
body: <pre><code>      function gallery_metabox_enqueue($hook) {
      if ( 'post.php' == $hook || 'post-new.php' == $hook ) {
        wp_enqueue_script('gallery-metabox', get_template_directory_uri() . '/gallery-metabox/js/gallery-metabox.js', array('jquery', 'jquery-ui-sortable'));
        wp_enqueue_style('gallery-metabox', get_template_directory_uri() . '/gallery-metabox/css/gallery-metabox.css');
      }
    }
    add_action('admin_enqueue_scripts', 'gallery_metabox_enqueue');
  
    function add_gallery_metabox($post_type) {
      $types = array('post', 'page', 'custom-post-type', 'gallery');
  
      if (in_array($post_type, $types)) {
        add_meta_box(
          'gallery-metabox',
          'Gallery',
          'gallery_meta_callback',
          $post_type,
          'normal',
          'high'
        );
      }
    }
    add_action('add_meta_boxes', 'add_gallery_metabox');
  
    function gallery_meta_callback($post) {
      wp_nonce_field( basename(__FILE__), 'gallery_meta_nonce' );
      $ids = get_post_meta($post-&gt;ID, 'vdw_gallery_id', true);
  
      ?&gt;
      &lt;table class="form-table"&gt;
        &lt;tr&gt;&lt;td&gt;
          &lt;a class="gallery-add button" href="#" data-uploader-title="Add image(s) to gallery" data-uploader-button-text="Add image(s)"&gt;Add image(s)&lt;/a&gt;
  
          &lt;ul id="gallery-metabox-list"&gt;
          &lt;?php if ($ids) : foreach ($ids as $key =&gt; $value) : $image = wp_get_attachment_image_src($value); ?&gt;
  
            &lt;li&gt;
              &lt;input type="hidden" name="vdw_gallery_id[&lt;?php echo $key; ?&gt;]" value="&lt;?php echo $value; ?&gt;"&gt;
              &lt;img class="image-preview" src="&lt;?php echo $image[0]; ?&gt;"&gt;
              &lt;a class="change-image button button-small" href="#" data-uploader-title="Change image" data-uploader-button-text="Change image"&gt;Change image&lt;/a&gt;&lt;br&gt;
              &lt;small&gt;&lt;a class="remove-image" href="#"&gt;Remove image&lt;/a&gt;&lt;/small&gt;
            &lt;/li&gt;
  
          &lt;?php endforeach; endif; ?&gt;
          &lt;/ul&gt;
  
        &lt;/td&gt;&lt;/tr&gt;
      &lt;/table&gt;
    &lt;?php }
  
    function gallery_meta_save($post_id) {
      if (!isset($_POST['gallery_meta_nonce']) || !wp_verify_nonce($_POST['gallery_meta_nonce'], basename(__FILE__))) return;
  
      if (!current_user_can('edit_post', $post_id)) return;
  
      if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) return;
  
      if(isset($_POST['vdw_gallery_id'])) {
        update_post_meta($post_id, 'vdw_gallery_id', $_POST['vdw_gallery_id']);
      } else {
        delete_post_meta($post_id, 'vdw_gallery_id');
      }
    }
    add_action('save_post', 'gallery_meta_save');
  </code></pre>
  
  <p>and in single.php</p>
  
  <pre><code>&lt;?php 
  $images = get_post_meta($post-&gt;ID, 'vdw_gallery_id', true);
  foreach ($images as $image) {
  
      ?&gt;
      &lt;img src="&lt;?php echo wp_get_attachment_url($image, 'large'); ?&gt; " ?&gt; " alt="" /&gt;                               
  
  
  
                                          &lt;a href="&lt;?php echo wp_get_attachment_image_url($image, 'full'); ?&gt; " data-rel="prettyPhoto[9788]" title=""&gt;&amp;nbsp;&lt;/a&gt;
                                                                      &lt;?php
  
  }
  ?&gt;
  </code></pre>
  
  <p>this is the code which works but only shows images. i want to have some captions for each image in the single post page. Each image should be displayed with their respective captions.</p>