Sauter la navigation

[Résolu] I need to get the IDs of the images of the repeateable image field

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

The issue here is that the user wanted to get the ID of his repeatable image fields.

Solution:
This can be done by using the code below.

// Put the code of your snippet below this comment.
function wp_get_image_ids() {
    $image_urls = get_post_meta( get_the_ID(),'wpcf-galleria-evento');
    $id_list = array();
     foreach ($image_urls as $image_url) {
         if(!empty($image_url)){
                 $attachment = attachment_url_to_postid($image_url);
                 array_push($id_list, $attachment);
             }
            }
 return implode(",", $id_list); 
}
add_shortcode( 'wp_get_image_ids', 'wp_get_image_ids' );

Just replace "wpcf-galleria-evento" with the slug of your repeatable image fields keeping the wpcf- prefix.

Add this to your custom code section in our Toolset -> Settings-> Custom Code and activate it.

Then you can just use the shortcode below to get the ID [wp_get_image_ids]

This support ticket is created Il y a 5 années et 5 mois. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Marqué : 

Ce sujet contient 4 réponses, a 2 voix.

Dernière mise à jour par francescoG-3 Il y a 5 années et 5 mois.

Assisté par: Shane.

Auteur
Publications
#1320241

Tell us what you are trying to do? I'm trying to create an image gallery slider using Divi Gallery Module and the repeatable image field. Divi Gallery Module works only with the image IDs

Is there any documentation that you are following? So, using the ACF gallery field, I can get them and you can see an example on the sidebar at lien caché. So, now I need not use ACF field, but use the Toolset repeatable image field because I will create a Front end Form to upload the images.

Is there a similar example that we can see? using the ACF gallery field you can see an example on the sidebar at lien caché

What is the link to your site? lien caché

#1320349

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Francesco,

I've updated the code a bit to make this easier to get the ids.



// Put the code of your snippet below this comment.
function id_galleria_evento() {
    $image_urls = get_post_meta( get_the_ID(),'wpcf-galleria-evento');
    $id_list = array();
     foreach ($image_urls as $image_url) {
         if(!empty($image_url)){
                 $attachment = attachment_url_to_postid($image_url);
                 array_push($id_list, $attachment);
             }
            }
 return implode(",", $id_list); 
}
add_shortcode( 'id-galleria-evento', 'id_galleria_evento' );

I noticed the issue with the parameters so I updated the code by hardcoding the gallery slug and the get id function and improved it to use the wordpress default attachment function.

Please let me know if this helps.
Thanks,
Shane

#1320363

Thank you, Shane,
now it works fine!!!

#1320375

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Francesco,

Awesome, you can go ahead and mark this ticket as resolved if there are no further questions on this 🙂

Thanks,
Shane

#1320469

My issue is resolved now. Thank you!