I have a post format gallery. I have created a metabox to add my images:
function mytheme_show_post_gallery_metabox( $post ) {
wp_nonce_field( 'mytheme_post_gallery_metabox', '_mytheme_post_gallery_metabox' );
$gallery = get_post_meta( $post->ID, '_mytheme_post_gallery', true );
?>
<a class="gallery-add button media-button button-primary button-large media-button-select" href="#" data-uploader-title="<?php _e( 'Add gallery images', 'mytheme' ); ?>" data-uploader-button-text="<?php _e( 'Add gallery images', 'mytheme' ); ?>"><?php _e( 'Add gallery images', 'mytheme' ); ?></a>
<table>
<tr>
<td>
<ul id="gallery-metabox-list">
<?php if ( $gallery ) : ?>
<?php foreach ( $gallery as $key => $value ) : $image = wp_get_attachment_image_src( $value ); ?>
<li>
<input type="hidden" name="_mytheme_post_gallery[<?php echo $key; ?>]" value="<?php echo $value; ?>">
<img class="image-preview" src="<?php echo $image[0]; ?>">
<a class="change-image" href="#"><?php _e( 'Change | ', 'mytheme' ); ?></a>
<a class="remove-image" href="#"><?php _e( 'Remove', 'mytheme' ); ?></a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</td>
</tr>
</table>
<?php
}
This code allows me to add images to my gallery through a metabox. I am now trying to also get the caption for each image. I have been trying quite a few approaches but no luck so far.. Any ideas would be much appreciated.