Hi. I want to take the ID's from a list of repeater images and put them into wordpress standard gallery shortcode:
<?php echo do_shortcode('[gallery ids="194"]');?>
but how do I get each image's ID?
Thanks
Dear Sam,
The image field stores the image URL, so it is not possible to get it directly via get_post_meta. You would have to do it the round way, like this:
function prefix_get_img_ids($post_id) {
$images = (array) get_post_meta($post_id, 'wpcf-rep-field', false); // cast to array in case there is only one item
$ids = array();
global $wpdb;
foreach($images as $img) {
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$img'";
$id = $wpdb->get_var($query);
$ids[] = $id;
}
return $ids;
}
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Paweł