Skip Navigation

[Resuelto] Displaying title OR caption OR description OR alt text for repeating image field

This support ticket is created hace 8 años, 9 meses. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Etiquetado: 

This topic contains 7 respuestas, has 2 mensajes.

Last updated by Simon hace 8 años, 8 meses.

Assisted by: Minesh.

Autor
Mensajes
#318935

I am trying to output images from a repeating image field with the alt text / title / caption included in the output.

All threads I have found refer back to this solution:

https://toolset.com/forums/topic/image-field-type-featured-image-how-can-i-display-image-title-alt-desc/#post-100666

but it's not working for me - the images are output but not the alt text (I have checked and my test images have ALL text fields completed).

An updated solution would be appreciated.

#318945

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello and thank you for contacting Toolset support.

Could you please tell me where exactly you are willing to display your images with its associated captions. Few screenshots will be helpful to understand your issue.

#318964

Hi Minesh,

Here's the page. At the moment the template is using some theme-specific code to output the images you can see here (with no alt tags). I want to replace that with the contents of the repeating image field 'wpcf-gallery-images' on the left of the page, with the title or caption for the image set both as the image alt tag and output below it in a <p>.

hidden link
hidden link

HTH

#319032

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

1)
As I understand you want to put existing set of image shown at left side + you want to add your repeating image field 'wpcf-gallery-images' on the left inside <p> tag

OR

you just want to show repeating image field 'wpcf-gallery-images' on the left inside <p> tag with alt and title tag.

2)
*** Please take FULL BACKUP of your database and your website.***
In order to investigate your issue if we require to check things on your install in order to see what could be going wrong there.

If you agree to this please use the form fields I have enabled below this comment box to provide temporary access details (wp-admin and FTP)?

I have set next reply as private.

#319057

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

As I understand now, you have created test page namely "test-for-toolset" and added gallery images to that pages, now you want to show this images with image title and alt tag and image title and alt tag should be equal to the page title, correct? if yes, could you please check now and see modifications done to your functions.php file or please let me know the corrections.

#322240

Hi Minesh, now the great Shortcode Crisis is over I'd like to get back to this.

What you have done is not solving my problem. I want to show the meta data from each piece of media with that media.

If you look at this image in the media library - hidden link - you can see that the title, caption, alt text and description are all set to:

'Moniack Mhor, sitting at 1000 feet, commands panoramic views of the local hills and countryside. The converted croft house and barn provides a cosy setting for writing courses and retreats throughout the year. Photographer: Nancy MacDonald'

THIS is the text I want to display, not the title of the page in which the image is embedded.

#322580

Minesh
Supporter

Languages: Inglés (English )

Timezone: Asia/Kolkata (GMT+05:30)

I debug your issue and found that actually why the code is not working when we compare "guid" field.

If you see post id = "228" in your database it has guid field value for post ID "228" with different domain name and when you saved types custom field image value its stored with different domain name.

I've modified the code in your functions.php file for now, could you please check and confirm its working for you as well.

#322684

Thanks - that does the trick. I should note the code was copied from the earlier post

https://toolset.com/forums/topic/image-field-type-featured-image-how-can-i-display-image-title-alt-desc/#post-100666

I imagine other users would find it helpful to see the amended function:

add_shortcode('my-images', 'my_images_shortcode');
function my_images_shortcode() {
global $post, $wpdb;
 
 $title =  get_the_title( $post->ID );
 
 
$images = get_post_meta($post->ID, 'wpcf-gallery-images', false);

$out = '<ul>';
foreach ($images as $image) {
	$x = explode("/",$image);
	$img = $x[5]."/".$x[6]."/".$x[7];
	
//$attachment_id = $wpdb->get_var($wpdb->prepare(
//"SELECT id FROM $wpdb->posts WHERE guid = %s",
//$image
//));

$attachment_id = $wpdb->get_var($wpdb->prepare(
"SELECT post_id FROM $wpdb->postmeta WHERE meta_value = %s",
$img
));

$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);

$out .= '<li><img src="' . $image . '" alt="' . $alt . '" title="' . $alt . '" /></li>';
}
$out .= '</ul>';
return $out;
}
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.