You can use gallery-metabox. Its open source and easy to use;
https://github.com/zulfnore/gallery-metabox
From Readme ;
Include the gallery.php
in your functions.php
:
require_once 'gallery-metabox/gallery.php';
Specify where you want the gallery metabox to show on line 17 in gallery.php
. You can pass an array to have it show up on multiple post types, custom post types are also allowed:
$types = array('post', 'page', 'custom-post-type');
In your template inside a loop, grab the IDs of all the images with the following:
$images = get_post_meta($post->ID, 'vdw_gallery_id', true);
Then you can loop through the IDs and call wp_get_attachment_link
or wp_get_attachment_image
to display the images with or without a link respectively:
foreach ($images as $image) {
echo wp_get_attachment_link($image, 'large');
// echo wp_get_attachment_image($image, 'large');
}