Problem: I would like to create a standard WordPress gallery using the gallery shortcode, and I would like to be able to provide a comma-separated list of image IDs. My images are stored as custom fields in a repeatable field group (RFG).
Solution: Use Views to query the RFG and output a list with separators. Use a custom shortcode to output the image ID in the loop.
Here's a shortcode that will return an image ID given a post ID and a field slug: [php] function wpt_get_img_id($atts) { global $post, $wpdb; $atts = shortcode_atts([ 'postid' => 0, 'fieldslug' => '', ], $atts); $postid = isset($atts['postid']) ? $atts['postid'] : $post->ID; $img = get_post_meta($postid, 'wpcf-' . $atts['fieldslug'], true); $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$img'"; $id = $wpdb->get_var($query); return $id; } add_shortcode("get_image_id", "wpt_get_img_id");
You would use it like this in a View:
[get_image_id postid="[wpv-post-id]" fieldslug="my-image-field"]
Relevant Documentation:
https://toolset.com/documentation/user-guides/view-layouts-101/#list-with-separators
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 |
---|---|---|---|---|---|---|
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 6 replies, has 2 voices.
Last updated by 5 years, 9 months ago.
Assisted by: Christian Cox.