I want to take the ID's from a list of repeater images and put them into wordpress standard gallery shortcode but in raw output format I get the link of each image in the repeater image field that I want.
How can I take the ID instead of the link for repeater image field?
Hello. Thank you for contacting the Toolset support.
As you can see that gallery shortcode works as given under:
[gallery ids="729,732,731,720"]
Where "ids" attribute have comma(,) separated IDs of images.
Could you please try following code - add the following code to your theme's functions.php file:
function prefix_get_img_ids($atts) {
$post_id= $atts["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 implode(",",$ids);
}
add_shortcode("get-image-ids", "prefix_get_img_ids");
[get-image-ids post_id="13"]
I hope this will fix your issue. Please let me know your feedback.
The code will be in a views template, so it will has to work for every post, so I cannot have a static post ID!
=> Are you using views to display post? which content template you are using.
=> Could you please tell me where exactly you would like to display gallery images?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
I've adjusted the code in your functions.php file as follows.
function prefix_get_img_ids($atts) {
global $post;
$images = (array) get_post_meta($post->ID, 'wpcf-gallery-images', 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 implode(",",$ids);
}
add_shortcode("get-image-ids", "prefix_get_img_ids");
In your content template - I've added code as follows:
The gallery images have big space between them and they are in columns of 3. How can I make that have smaller margin and be as more columns as the width allows?
If you still need further assistance, for your any custom programming need, please feel free to contact our certified partners: https://toolset.com/consultant/
Please open a new ticket for your each new question. This will help other users with similar problems to find solutions when searching the forum.
Thank you for your understanding.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.