Navigation überspringen

[Gelöst] Get ID’s of gallery image (repeating field)

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 5 replies, hat 1 Stimme.

Zuletzt aktualisiert von - 1 week ago.

Assistiert von: Minesh.

Author
Artikel
#2889118

I want to retrieve the id's of the images I set with a repeating image field

I checked the documentation for 2 hours

Is there a similar example that we can see?
No

What is the link to your site?
Not live

#2889119

Forgot to mention: I want to do that in PHP, will not us a content template or view.
I do this:
$ts_gallery_images = types_render_field('docenten-afbeelding', array("output"=>"raw"));
But I do not seem to have the option to get the ID's, only the URL's or the image.

Kind regards, Han

#2889251

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The repeating image field content stored in postmeta table. Do you want the post meta ID or the actual uploaded image attachment ID?

#2889947

Hi, I want the actual uploaded image attachment ID.
But this night I found a solution (But it might not be the best way?)
Please let me know if there is a beter solution.

Regards, Han

// Toolset get gallery id's van docenten
function inside_ts_gallery_ids($attrs) {
if (isset($attrs['module_class'])
&& strpos($attrs['module_class'], 'ts-gallery') !== false
&& function_exists('types_render_field')
) {
global $wpdb;
$table_name = $wpdb->prefix . 'toolset_post_guid_id';
$ts_gallery_images = types_render_field('docenten-afbeelding', array('output' => 'raw'));

if ($ts_gallery_images) {
$ts_gallery_urls = [];
$ts_gallery_urls = explode(' ', $ts_gallery_images);
$ts_image_ids = [];
foreach ($ts_gallery_urls as $ts_url) {
$ts_images = $wpdb->get_results(
$wpdb->prepare( "SELECT post_id FROM $table_name WHERE guid = '$ts_url'" ) );
foreach ($ts_images as $ts_image) {
$ts_image_ids[] = $ts_image->post_id;
}
}
$attrs['gallery_ids'] = implode(',', $ts_image_ids);
}
}
return $attrs;
}
add_filter('et_pb_module_shortcode_attributes', 'inside_ts_gallery_ids');

#2889951

Minesh
Unterstützer

The code you shared seems to be ok but there are multiple ways, its on you what method. you want to chose.

Here is a related ticket that might help you:
- https://toolset.com/forums/topic/images-gallery-missing/
- https://toolset.com/forums/topic/re-ordering-image-fieldallow-multiple-instances-not-working/#post-2808003

You can adjust the code where/if required.

#2889954

Thanks Minesh, very useful!
Regards, Han