Problem:
I would like the user to be able to upload a file into a post. The field is set to allow multiple entries.
I would like the form to allow the user to upload a new file without displaying (and allowing for the deletion of) files already stored in that field for that post. So, the option would be simply to "add new". Is that possible
Solution:
That's actually not possible. But you can use two repeatable image fields and some custom code to achieve this. For example, create two repeatable image fields:
- Field Images, which will actually hold the images.
- Field Temporary_images, which will be used in the form each time.
And upon form submission, you can implement custom code that will hook into the cred_save_data action, then you can copy the values of the "Temporary_images" field into the "Images" field, and empty the values of the "Temporary_images" field. Does it make sense?
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
The custom code will be using WordPress functions, get_post_meta, and update_post_meta. Note that Toolset adds a prefix to the meta key "wpcf-". Read more about it here https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/
- https://developer.wordpress.org/reference/functions/get_post_meta/
- https://developer.wordpress.org/reference/functions/update_post_meta/
Relevant Documentation:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
- https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/
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 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
This topic contains 2 replies, has 2 voices.
Last updated by 3 years, 11 months ago.
Assisted by: Jamal.