Problem: I would like to display a gallery of images for each post, and I would like for my site users to be able to create posts with image galleries.
Solution: Use a repeating image custom field to allow your user to upload several images to place in a gallery. Use the WordPress gallery shortcode to display those images. Add the following code to functions.php:
function prefix_get_img_ids($atts) { global $post; $postid = isset($atts['post_id']) ? $atts['post_id'] : $post->ID; $images[] = get_post_meta($postid, 'wpcf-repeating-image-slug', true); $ids = array(); global $wpdb; foreach($images as $img) { $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$img'"; $id = $wpdb->get_var($query); if($id) $ids[] = $id; } return implode(",",$ids); } add_shortcode("get_image_ids", "prefix_get_img_ids");
Then use the gallery shortcode like so:
[gallery ids="[get_image_ids post_id='[wpv-post-id]']"]
Relevant Documentation: https://toolset.com/documentation/user-guides/repeating-fields/
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.
Our next available supporter will start replying to tickets in about 2.19 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 7 years, 3 months ago.
Assisted by: Christian Cox.