May 31, 2013

WordPress Plugin – WP Simple Galleries – Images Helper Function

WordPress Plugin – WP Simple Galleries – Images Helper Function

I have written this function for myself to use in a module. I was not require any shortcode so my requirement was like this. Have a look, might it will work for you as well.

if(!function_exists('wp_simple_gallery_images')){
function wp_simple_gallery_images($post_id)
{
$images = array();
$post_meta = get_post_meta($post_id, 'wpsimplegallery_gallery', true);
if(!empty($post_meta)){
foreach($post_meta as $key){
$images[$post_id][] = get_post_meta($key, '_wp_attached_file', true); }
}
return $images;
}
}

Modified:

if(!function_exists('wp_simple_gallery_images'))
{
function wp_simple_gallery_images($post_id)
{
$images = array();
$post_meta = get_post_meta($post_id, 'wpsimplegallery_gallery', true);
$post_meta = is_array($post_meta)?$post_meta:array();
if(!empty($post_meta))
{
foreach($post_meta as $attachment_id)
{
$attachment_data = get_post($attachment_id);
$images[$post_id][$attachment_id]['src'] = $attachment_data->guid;
$images[$post_id][$attachment_id]['caption'] = $attachment_data->post_excerpt;
}
}
return $images;
}
}

Link: Support – WP Simple Galleries

Last updated: March 19, 2014