I am having trouble getting this to work. I have searched this forum and found a shortcode that displays the title, and it kinda works, except, it shows the same title for each image, rather than the specific title for each image.
/* SHORTCODE -- Get Repeating Field Title
==============================================*/
add_shortcode('get_media_title', 'get_media_title_func');
function get_media_title_func() {
global $post, $wpdb;
$images = get_post_meta($post->ID, 'wpcf-gallery', false);
foreach ($images as $image) {
$attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid = %s",$image));
$title = get_the_title($attachment_id);
}
return $title;
}
I must apologize for the delay, however here is the code that you will need.
/* SHORTCODE -- Get Repeating Field Title
==============================================*/
add_shortcode('get_media_title', 'get_media_title_func');
function get_media_title_func() {
global $post, $wpdb;
// Attributes
$image_urls = get_post_meta($post->ID, 'wpcf-image', false);
$links = "";
$index = 0;
foreach ($image_urls as $image_url) {
if(!empty($image_url)){
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
$links .= "<a rel='lightbox' data-rel='lightbox-gallery-1' href='".do_shortcode("[types field='image' size='full' index='".$index."' url='true'][/types]")."'>".do_shortcode("[types field='image' alt='%%ALT%%' title='%%TITLE%%' index='".$index."' size='custom' width='200' height='150' align='none' resize='crop' ][/types]")."</a>".get_the_title($attachment[0])."</a> ";
}
$index ++;
}
return $links;
}
You wont need to use the for each shortcode because i've already done this in the code. So just use the shortcode [get_media_title] and it will return the images and the title as well.