Skip Navigation

[Closed] How to get ID's of repeating images

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

This topic contains 1 reply, has 2 voices.

Last updated by Paweł Pela 9 years, 9 months ago.

Assisted by: Paweł Pela.

Author
Posts
#233090

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

#233143

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ł

The topic ‘[Closed] How to get ID's of repeating images’ is closed to new replies.