hi, are you on holiday or something?
if yes i don't want to disturb you either.
Hi Dee,
Thank you for waiting and no I'm not on holidays.
I did some research and WordPress offers some relatively newer functions, which can be used to first get the ID of image attachment and then it's caption text:
1. attachment_url_to_postid - https://developer.wordpress.org/reference/functions/attachment_url_to_postid/
2. wp_get_attachment_caption - https://developer.wordpress.org/reference/functions/wp_get_attachment_caption/
The shortcode code can be updated to:
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;
}
}
This approach is better than querying data directly from the database and should improve performance too.
Please let me know how it goes.
regards,
Waqar
Hi. the solution is not working for swiper but working on flickity slider. , pls feel free to test on my site.
Hi Dee,
I noticed that in your content template "DV Swiper Slider" ( hidden link ), a very long content was wrapped inside a conditional block, which is not recommended.
( ref: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ )
I've broken it down into smaller chunks and the shortcodes inside are now working from that template too. I'm sorry, I should've spotted that issue earlier and this seems to be the reason why I was not able to reproduce this on my own test website.
regards,
Waqar
My issue is resolved now. Thank you Waqar .
Thanks for the update Dee and glad the issue is resolved now.
Note: You can also close the other ticket, related to this topic:
https://toolset.com/forums/topic/caption-is-not-working-for-multiple-image-field-for-more-then-3-images/
regards,
Waqar