Skip Navigation

[Résolu] How to build a gallery in Toolset

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

Problem:
How could we build a gallery of Image Fields without the need of adding a single image field for each gallery image item?

Solution:
You can create a repeating custom image field and add as many images to a post as you want in that specific gallery later.
Then, use the Repeating Field / Gallery block to display those repeating images in a gallery that you can customize.

Relevant Documentation:
https://toolset.com/documentation/user-guides/custom-content/create-image-galleries-using-toolset-and-custom-fields/

This support ticket is created Il y a 4 années et 9 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

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

Dernière mise à jour par Tom Gonzales Il y a 4 années et 9 mois.

Assisté par: Beda.

Auteur
Publications
#1488993
sample-image-extra-image-upload4.png
sample-image-extra-image-upload3.png
sample-image-extra-image-upload2.png
sample-image-extra-image-upload.png

I am trying to: update/replace existing images in a custom post type - Kids Camps - using a CRED form modified to add the images and automatically create an image gallery on the frontend. This feature was working fine until recent Toolset updates.

Link to a page where the issue can be seen: lien caché

I expected to see: 6 images loaded in the backend, only seeing 4 images on the frontend.
Instead, I got: Plus when one of our editors tried to upload new images, the new images just got added to the existing images on the front end, even though in the CMS edit for the listing, it only showed the maximum 8 images allowed - but on the frontend, there were 11 images. I had to download the images again and then reload them to the image library, and this removed the extra images created by the previous upload, but now only 4 images are showing on the frontend.

I'm using a custom script in my function.php file (originally provided by Toolset support) to automatically create the image galleries from the CRED form (see attached image).

#1489245

Can you link me to where that custom script was created?
This is not how a custom code shall be created and we do not, by support policy, provide custom code.

Note that the code repeats the lines over and over. This is not how PHP should be coded.
And, as stated before, we cannot assist the Custom Code. We can only guide you through the Toolset API.

That code does not use any Toolset API and is not related to Toolset Forms.
It gets eventual Fields, from the database, not from any Form, and does a SQL Query in the middle of the ShortCode, to get the Guids, and then returns that in a ShortCode "get_image_ids"

We cannot support this as it is simply not related to Toolset at all.
I see you use Toolset fields, but the entire logic and output of that Code is not based on Toolset - you can do the exact same with any other Field (not from Toolset) and still would run into the exact same issues, as our Image field is just a native WordPress Custom Field.

I am also not sure what you try to achieve, as Galleries are not created by Toolset like that.
Instead, you could use a repeating Image field and use that in a Form to add many images.
Then with the Repeating Fields Image Gallery feature that Toolset offers, you can create galleries with them

The code you have now cannot be stopped or broken by Toolset, as it does not use its API and the value of the fields is basically just an URL to the Image, so if that stayed the same, the code would still (independent from Toolset) work
But as said, I am not sure what it does, as it is not using any Toolset Feature or API.

If you create custom galleries with this I recommend consulting a contractor for the custom code part.
https://toolset.com/contractors/

If instead you have issues with the Form, which should upload an image or many, and it does not work, I can take a look but would need to have either the steps to replicate or a copy of the site (https://toolset.com/faq/provide-supporters-copy-site/) where that happens, as I cannot replicate such issue locally.

Thanks!

#1492677

Beda - this is where I originally got the code to implement the current solution.

https://toolset.com/forums/topic/is-it-possible-to-use-custom-post-fields-within-a-wordpress-shortcode/

If you know of a better way to accomplish this without having to change everything in all my listings across several sites, I'm all ears.

#1492691

And the issue I'm having now is that when I try to update or delete the images or delete images in the CMS using the CRED form and the toolset image fields (not a repeating image field but individual image fields like kc-extra-image-1, kc-extra-image-2, kc-extra-image-3, and so on), the images either don't always appear correctly on the frontend (sometimes duplicate images appear in the gallery or some are missing - refer to sample image uploads for an example). The form was working fine whether creating new listings and adding new images or editing existing images (replacing them) since the custom code used is calling to the post ID and the toolset image field name to create the gallery. But not it's having issues.

#1493393

OK, the code from https://toolset.com/forums/topic/is-it-possible-to-use-custom-post-fields-within-a-wordpress-shortcode/ is a ShortCode.
You insert this somewhere with [gallery ids="[get_image_ids post_id='12345']"]
Meaning, you build a WordPress gallery, where the IDs of the Images for it come from get_image_ids shortcode, where post_id needs to be the very post where those images are stored.

So far so good.
The code gets the values from SINGLE image fields and puts those in an array.
Then it grabs the IDs of those images by their URL.

That should work for SINGLE Image fields, it is totally unrelated to repeating image fields.

I see you mention this stopped working after Toolset Updates, but it is custom code and I can't really assist its maintenance, or creation, see https://toolset.com/toolset-support-policy/, but I can help investigate what is wrong.

For this, I'll need to A) set up this locally and see if it works and then B) check why does it not work on your site, but we do not do Custom Code support at Toolset - so this is something I will need some cooperation from your side to avoid spending time on things I am not allowed to do, technically.

Could you maybe create a duplicate with your site, following https://toolset.com/faq/provide-supporters-copy-site/, and then send that to me, along with precise instructions where I can see and adjust the issue?
I can then take a look.

Generally, though, you should use Repeating Fields, and then use a Repeating Fields gallery Block to display them - this is how galleries are made with Toolset.
If you want something else, you'd have to suggest it at https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1494877

Thanks for the breakdown, Beda - I never implied there was an issue with repeating fields since the form is using single image fields, and not sure why no one mentioned using the repeating fields to build galleries back when I originally implemented the code back in July of 2017. Perhaps that wasn't an option back then? Regardless, I'm only experiencing this issue on one of the sites where I'm using this same code/solution, so I'm going back through all the plugins (which I've pretty much ruled out) and the theme. It might be a theme conflict. Either way, let's close out this ticket since I don't want to waste your time, and I'll keep working on it from my end, and I might go ahead and implement the Toolset solution for creating galleries. Thanks for your time!

Tom

#1495377

Beda - so I was able to add the Toolset image gallery solution to my directory listing and it's working nicely, so now I just need to update my active listing so they are all using the new image gallery format. But I have a question.

lien caché

Is it possible to limit the number of images in a repeating field? Right now we only allow up to 8 images in an images gallery. Can we still limit the number of extra images in a repeating image field?

Tom

#1495785

I understand you switched to use the Repeating Fields gallery block?
That's great, I use it as well on my sites: I think it is one of the truly great innovations in the whole "blocks thing".

It is not possible to limit the number of items that you can add to a repeating field with any setting in Toolset, unfortunately.

It is actually a widely requested feature and I forwarded this and asked for implementing something if possible, but please if you don't mind to also suggest it to https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/ so eventually Product Management can implement such feature, this would help.

Right now for this, you'd need Custom JS code, see https://toolset.com/forums/topic/repeaters/, https://toolset.com/forums/topic/upload-gallery/

I think it should also be possible to control this with the cred_save_data or similar hook, but that is a PHP validation, which would fire after we press submit and the form initially submits - not like the JS solution which completely disables you from adding more or less than a specified amount of items

Let me know if you need more help with this, or have specific questions about it.
Unfortunately this as well custom code, that we can support only limitedly.

#1506161

My issue is resolved now. Thank you!