Problem:
I need help to get the images ids from repeatable field to create WordPress gallery to have like this shortcode:
[gallery ids="175,174,171,172"]
Solution:
There isn't such a feature within Types plugin, see our document:
https://toolset.com/documentation/customizing-sites-using-php/functions/#image
There isn't such an option can output the attachment image ID as the result.
And Types image field stores the image URL in the database.
I suggest you create another shortcode for it, see wordpress document:
http://codex.wordpress.org/Function_Reference/add_shortcode
For example:
1) Add below codes into your theme/functions.php
add_shortcode('repeating-images-gallery', 'repeating_images_gallery_func'); function repeating_images_gallery_func($atts, $content) { global $post, $wpdb; $images = get_post_meta($post->ID, 'wpcf-my-slide', false); $ids = array(); foreach ($images as $image) { $attachment_id = $wpdb->get_var($wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid = %s", $image )); $ids[] = $attachment_id; } $out = do_shortcode('[gallery ids="' . implode(",", $ids) . '"]'); return $out; }
2) Put the gallery shortcode like this:
[repeating-images-gallery]
And we have [wpv-for-each] shortcode, you can use it to display all images in the repeatable field
Relevant Documentation:
https://toolset.com/documentation/views-shortcodes/#wpv-for-each
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
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/Hong_Kong (GMT+08:00)
This topic contains 4 réponses, has 2 voix.
Last updated by saidB1322 Il y a 7 années et 9 mois.
Assisted by: Luo Yang.
Le forum ‘Types Community Support’ est fermé à de nouveaux sujets et réponses.