Skip Navigation

[Resolved] Displaying Caption or Title of multiple-instances image field ?

This support ticket is created 7 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by justinm-4 7 years, 7 months ago.

Assisted by: Konstantinos Galanakis.

Author
Posts
#444816
Screen Shot 2016-10-10 at 2.59.25 PM.png
Screen Shot 2016-10-10 at 2.46.58 PM.png

I am trying to: Display title or caption for multiple-instances image field. I used a few custom shortcodes provided by 2 year-old solutions, without success.

I visited this URL: https://toolset.com/forums/topic/displaying-title-or-caption-or-description-or-alt-text-for-repeating-image-field/
and
https://toolset.com/forums/topic/how-to-retrieve-image-caption-alt-text-and-description/

Also tried the toolset « Display options for this field».

After looking for a solution for a few hours, I just want to make sure I am not missing anything here ..

I expected to see: The caption or title displayed under the image.

Instead, I got:

#445177

Hello.

Thank you for contacting the Toolset Support.

The title field you are modifying in your second screenshot is for the title tag of the hyperlink that will lead to the image itself. It has nothing to do with what will be displayed around the image.

If you want to add title and caption right below the image, you will need to create a custom shortcode. Taking the code of Luo Yang from the second link you are posting, and modifying it to suit your needs, we conclude to the code below.

add_shortcode('get_media_info', 'get_media_info_func');
function get_media_info_func($atts){

   global $wpdb;
   $atts = shortcode_atts( array(
       'field' => '',
       'display_size' => 'thumbnail',
       'linkto_size' => 'full',
   ), $atts );
   $my_field = new WPCF_Repeater();
   $my_field->set(get_the_ID(), wpcf_admin_fields_get_field($atts['field']));
   $get_meta = $my_field->_get_meta();
   $arr = array();
   $res = '';
   if(isset($get_meta['custom_order'])){
       foreach($get_meta['custom_order'] as $k => $v ){
           $attachment_id = wpcf_image_is_attachment($v);
           $display_image = wp_get_attachment_image_src($attachment_id, $atts['display_size']);
           $linkto_image = wp_get_attachment_image_src($attachment_id, $atts['linkto_size']);
           $title = get_the_title($attachment_id);
           $caption = get_the_excerpt($attachment_id);
           $description = get_the_content($attachment_id);
           $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
           $format = '<a href="%s"><img src="%s" alt="%s" title="%s" caption="%s" /></a><p><strong>%s</strong><br /><em>%s</em></p>';
           $res .= sprintf($format, $linkto_image[0], $display_image[0], $alt, $title, $caption, $title, $caption);
       }
   }
   return $res;
}

Now, to use this shortcode, inside your View or Content Template, where you want your images to be displayed, add this

[get_media_info field='image']

where:
“Image” is the slug of your repetitive custom field for images.

If you have any further issues, please let me know.

Regards

#445224

Works like a charm, thanks so much !

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.