Skip Navigation

[Resolved] Trying to get caption from multiple images

This support ticket is created 5 years 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Tagged: 

This topic contains 3 replies, has 3 voices.

Last updated by Waqar 5 years ago.

Assisted by: Waqar.

Author
Posts
#1388709

Hi!

This is what I have done:

<section id="app" class="detail [wpv-post-taxonomy type="artdesortes" format="slug" separator=" "]">
			<section class="container pic-wrapper clearfix">
				<ul class="owl-carousel pic-carousel">		
					<li class="item">
                      [types field='bild' size='full' alt='%%ALT%%' title='%%TITLE%% - %%DESCRIPTION%% - %%CAPTION%%' align='none' separator='</li><li class="item">']xx[/types]
              </li>               
          </ul>

Works fine with owl slider with multiple images in a CPT.

Tell us what you are trying to do?
I need the %%CAPTION%% from every image for copyright purposes.

Either like this:
<img … data-caption=„%%CAPTION%%“>

or this:
<figure>
<img …>
<figcaption>%%CAPTION%%</figcaption>
</figure>

Is there any documentation that you are following?
I tryed this in multiple variations:
https://toolset.com/forums/topic/displaying-caption-from-media-post/

Is there a similar example that we can see?

What is the link to your site?
My site is non publicly online yet.

#1389011

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Fabian,

Thank you for getting int ouch.

I'm not sure what you want to achieve with the caption.

Is it that you want to be able to add it here ?
<figcaption>%%CAPTION%%</figcaption>

Please provide a little bit more information on the exact setup and scenario that you want to use this in.

Thanks,
Shane

#1390915

Dear Shane,

this is exactly, what I am tyring to to: I need to output the caption in any way, either als datacaption in the img-tag or as <figcaption>%%CAPTION%%</figcaption> outside the img-tag.

Thanks in advance.

Theo

#1392393

Hi Theo,

Thanks for writing back.

Shane is on vacation and will be back next week, so I'll be following up on this ticket.

To fetch the caption text from an image/file, you can register a custom shortcode, that can accept its URL and then return the caption text.

Example:


add_shortcode( 'ts_caption_new', 'ts_caption_new_func');
function ts_caption_new_func($atts)
{
    $url = $atts['url'];
 
    $image_id = attachment_url_to_postid( $url );
 
    if($image_id > 0) {
        $image_caption = wp_get_attachment_caption($image_id);
    }
    if ($image_caption) {
        return $image_caption;
    }
}

Note: The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.

After that, you'll be able to call the caption text for each image/file from the repeating custom field like this:
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each )


[wpv-for-each field="wpcf-field-slug"]
URL: [types field='field-slug' output='raw'][/types]<br>
Caption: [ts_caption_new url="[types field='field-slug' output='raw'][/types]"]<hr>
[/wpv-for-each]

Please replace "field-slug" with the actual slug of your image/file field and you'll have the flexibility to build the HTML output as needed.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar