cmb-field-gallery
cmb-field-gallery copied to clipboard
Add a clear gallery button
Hi mustardBees
Where I need to add a clear gallery button?
Thanks! Chris
That's the one to-do item in the read me file!
A workaround for now would be to clear the hidden text field manually. It'd be possible to add another button to do this. However, before I go down this route I'm going to take a look and see if there is a smarter way to work with the media manager.
Hi, when the gallery screen opens up, by default all of the images in the media library are automatically selected for the gallery. Then I have to go through and remove the images I dont want in the gallery. Is it supposed to work like this? thanks
Having the same problem as @jajouka79
I was able to work around this issue by editing the following line in cmb-field-gallery.php:
echo ' <input type="hidden" id="' . $field->args( 'id' ) . '" name="' . $field->args( 'id' ) . '" value="' . $meta . '" />';
to:
// get the gallery images for the current post
$gallery_images = get_post_meta( get_the_ID(), 'WHATEVER_KEY_YOU_SETUP', true ); ?>
<?php if ( ! empty( $gallery_images )) {
// if a gallery already exists for this post, then pass the image id's via hidden input
echo ' <input type="hidden" id="' . $field->args( 'id' ) . '" name="' . $field->args( 'id' ) . '" value="' . $meta . '" />';
} else {
// if the gallery is empty, set the hidden input value to "0"
echo ' <input type="hidden" id="' . $field->args( 'id' ) . '" name="' . $field->args( 'id' ) . '" value="0" />';
}
Not necessarily the correct way to do it... but it works for me and will hopefully help someone else.
I'm still trying to find a way to make the gallery editor open directly to either the library or upload tab if the gallery is empty. If anyone has any input on how to accomplish that, please chime in.
Thank you @mustardBees for the great addition to CMB!