Last active
August 29, 2015 14:16
-
-
Save jprieton/8fb2f8ac230a44435ca1 to your computer and use it in GitHub Desktop.
Gallery Meta Box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('rwmb_meta_boxes', function ($meta_boxes) { | |
$meta_boxes[] = array( | |
'id' => 'gallery', | |
'title' => 'Galería', | |
'pages' => array('page'), | |
'context' => 'normal', | |
'priority' => 'high', | |
'fields' => array( | |
array( | |
'id' => 'post_gallery', | |
'type' => 'file_advanced', | |
// 'max_file_uploads' => 1, | |
), | |
) | |
); | |
return $meta_boxes; | |
}); | |
/** | |
* | |
* @param int $post_id | |
* @return string|bool | |
*/ | |
function get_gallery_shortcode($post_id = 0) { | |
$gallery_ids = get_gallery_ids($post_id = 0); | |
return !empty($gallery_ids) ? sprintf('[gallery ids="%s"]', implode(',', $gallery_ids)) : FALSE; | |
} | |
/** | |
* | |
* @param type $post_id | |
* @return type | |
*/ | |
function get_gallery_ids($post_id = 0) { | |
$post_id = (is_numeric($post_id) && 0 < $post_id) ? (int) $post_id : get_the_ID(); | |
return get_post_meta(get_the_ID(),'post_gallery'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment