Hello and thank you for contacting the Toolset support.
From what I understand so far, there are two problems involved, please correct me if I am wrong:
- Deleted images from Toolset fields still appear in the result of the [gallery] shortcode.
- Limiting the instance of a repeatable image field.
I'll try to discuss both cases below and suggest solutions for each. If I missed something, let me know about it or create a new ticket for it.
Deleted images from Toolset fields still appear in the result of the [gallery] shortcode.
I believe it is a WordPress behavior rather than a Toolset one. When you attach an image to a post(inside the editor, or as featured image, or using Toolset), the image is saved in the database as an attachment and the parent_post is the post where it is added. But when the image is not used anymore, the parent_post is not removed, that's why it still appears in the [gallery] shortcode results. You can remove these unattached images manually or using a plugin:
- hidden link
- https://wordpress.org/plugins/media-cleaner/
As a solution, I would suggest using the "include" attribute of the [gallery] shortcode.
[gallery ids="729,732,731,720"]
I'll explain later how to get the ids from a repeating field and you can adapt it to use it for a regular image field.
Limiting the instance of a repeatable image field.
There is no built-in solution for this. But you can limit the form to a min-max number of instances with custom Javascript. Check these forum threads, you may adopt/adapt their solutions to your case:
- https://toolset.com/forums/topic/limit-number-of-instances-for-two-different-custom-fields/
- https://toolset.com/forums/topic/repeaters/
If you use a repeating field and you would like to get the ids of the images for the [gallery] shortcode, you will need to create a custom shortcode that will calculate it. Check this forum ticket https://toolset.com/forums/topic/get-id-of-repeater-image-field-insted-of-url/
I hope this helps. Let me know if you have any questions.