Skip Navigation

[Resolved] To show an image ID inside a third party shortcode

This thread is resolved. Here is a description of the problem and solution.

Problem:
To show an image ID inside a third party shortcode

Solution:
User shared the solution with the following reply.

You can find proposed solution in this case with the following reply:
https://toolset.com/forums/topic/to-show-an-image-id-inside-a-third-party-shortcode/#post-2067065

Relevant Documentation:

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

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)

This topic contains 3 replies, has 2 voices.

Last updated by Jonathon Hanten 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2066975
Screen Shot 2021-05-24 at 7.06.57 PM.png
Screen Shot 2021-05-24 at 7.05.57 PM.png

Tell us what you are trying to do?

The problem I have is that the image field doesn't have an option to provide the image ID which is required by the VC shortcode.
I'm rather disappointed because this option for image fields I have found reference to back in 2016 as a future feature.

I thought I had solved my problem when I found this code: https://toolset.com/forums/topic/get-id-of-attachment/

The function and shortcode provided does work to give me the information I need. My problem now is that if I try to add it in as a third level of shortcode it breaks the view.

[vc_video link="[types field='video-url' output='raw'][/types]" custom_thumbnail="true" play_icon_animation="scale-up" thumbnail_image="[get-image-id url='[types field='thumbnail-image' output='raw']']"]

The thumbnail_image parameter uses an images ID. which I haven't found any other way to get then creating a shortcode.

Do you see something I missed? I mean how else would use use the code you provided, but inside a third level shortcode?

Is there any documentation that you are following?

https://toolset.com/forums/topic/get-id-of-attachment/

Is there a similar example that we can see?

What is the link to your site?

hidden link It is in the section labeled Featured Video on the right towards the bottom of the homepage.

My goal is to speed up the site by using thumbnails for all videos so Vimeo doesn't have to load so much code on the page. So I created an image field inside my custom post type for videos and am trying to use the VC built in support for thumbnails that open into a lightbox to play the video. I just need to be able to spoon feed it the correct information.

Here is the whole view code if it helps:

[wpv-conditional if="( $(wpcf-thumbnail-image) ne '' )"][vc_row][vc_column][vc_video link="[types field='video-url' output='raw'][/types]" custom_thumbnail="true" play_icon_animation="scale-up" thumbnail_image="[get-image-id url='[types field='thumbnail-image' output='raw']']"][/vc_column][/vc_row][/wpv-conditional]
[wpv-conditional if="( $(wpcf-thumbnail-image) eq '' )"][vc_row][vc_column][vc_video link="[types field='video-url' output='raw'][/types]"][/vc_column][/vc_row][/wpv-conditional]
Show code: [get-image-id url='[types field='thumbnail-image' output='raw']']

The attached images shows what the view does if I remove the [get-image-id] shortcode and just put in the image id directly. The show code was my proof that the get-image-id shortcode works.

Any advice would be greatly appreciated. I'm kind of stumped.

#2067065

Since posting my question I also came across this entry.
https://toolset.com/forums/topic/image-ids-inside-vc_gallery/

Which lead me to recreating the vc shortcode I needed in a function. I followed that up with this article I found
hidden link which had a function that I could use with my own created function to get the ID (you all should give directly as an output option) so hopefully this will help others.

Here is the shortcode function I created along with the function from the wpscholar.com link.

// Add Shortcode to generate VC's Video Player Element
function display_vc_videov2( $atts ) { 
    // Attributes
    $atts = shortcode_atts(
        array(
            'video' => '',
            'thumb' => ''
        ), $atts     );
    $image_id = get_attachment_id( $atts['thumb'] );
    return do_shortcode('[vc_video link='. $atts['video'] . ' custom_thumbnail="true" play_icon_animation="scale-up" thumbnail_image="'. $image_id . '"]'); 
}
add_shortcode( 'display_vc_videov2', 'display_vc_videov2' );
#2067415

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Thank you for sharing the solution. It seems you already found the solution. Let me know if you still needs assistance or you are welcome to close this ticket.

#2067711

My issue is resolved now. Thank you! I still think the ID of an image should be an option directly from the Toolset shortcode instead of having to go through all this trouble.