Skip Navigation

[Resolved] Images in Visual Composer

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

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by marcB-6 7 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#457547

Hi guys!

On a website i'm building i created i post type called 'voorstellingen'. In this post type the admin can choose four images.

I'm trying to create a content template with an image grid where these four images show up. You can see the grid with four images over here: hidden link

I used the visual composer to build the content template. Visual composer uses the image ID to load the right images. The shortcode looks like this: [vc_gallery type="image_grid" images="104,103,102,14" layout="4" gallery_style="3" load_in_animation="fade_in" img_size="600x600"]

I'm wondering how i can retrieve the image id's of the chosen images in a post. And how i can plot these in the shortcode (what would the shortcode look like?).

Hope you can help!
Marc

#457583

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Marc

There isn't a Toolset way of doing this, but you could write some non-trivial custom code to achieve it.

The problem is that when you add image custom fields to a post using Types it stores the url of the uploaded image as post meta against the post. It doesn't record the id of the media post which WordPress generates anywhere.

So, it is not simply a question of what shortcode can be used to output the id of the attachment posts, it is that Toolset doesn't know what the ids are because it doesn't use them or store them.

A solution would require:

- for the current post in the loop (where your VC shortcode is added), get the urls of the image fields from wp_postmeta
- work backwards from those urls to find the ids of the attachment posts
- output/return those ids to the vc shortcode

So you would need to write a custom shortcode "attachment_ids" to achieve this that you could insert into your vc shortcode, something like:

[vc_gallery type="image_grid" images="[attachment_ids]" ... ]

But before going very far down that route I would double check that the vc shortcode will work with a nested shortcode in that way, by writing a custom shortcode that simply returns a hard-coded string with your four ids as per the example in your question.

You can read about writing custom shortcodes here:
https://developer.wordpress.org/plugins/shortcodes/

And as for working backwards to get the post ids from the image urls, try this:
hidden link

#457645

Hi Nigel,
Clear! Since it's just a simple grid i rebuild it in HTML. Much more easier.
Thanks!
Marc

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