Skip Navigation

[Résolu] Form with Recurring date / Entry

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

Problem:
The user has a form that creates a post and asks if he can implement a recurring post feature. For example, create a post for a user that has date times set for every Monday until next month

Solution:
First of all, note that a Toolset form is meant to create or edit only ONE post. To be able to create multiple posts, you will need to create custom code hooked to the cred_save_data action, that will create the additional posts.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

To pass data from the form to your action function, you can use generic fields.

Now, it is a matter of how you intend to do it. You may want to calculate the additional posts' arrival and departure dates/times on the frontend with Javascript, and pass them to the action function.
Or you may want to pass the rule(every week until a certain date) and calculate the date on the server end inside your action function.

Then you can create additional posts with the wp_insert_post function. https://developer.wordpress.org/reference/functions/wp_insert_post/
And update the post custom fields values with the update_post_meta function. https://developer.wordpress.org/reference/functions/update_post_meta/
Note that you will need to refix your fields with "wpcf-". Check the first section of this page https://toolset.com/documentation/customizing-sites-using-php/functions/

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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+00:00)

This topic contains 3 réponses, has 2 voix.

Last updated by leilaG Il y a 3 années et 6 mois.

Assisted by: Jamal.

Auteur
Publications
#1781449

Hi, we have a form the we add visitors with Arrival and Departure dates. These are then listed in a VIEW. Some visitors attend on a regular basis for example every Monday.

Is there a solution to add this as an option when a person is adding a visitor through the form?

#1781541

Jamal
Supporter

Languages: Anglais (English ) Français (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

I am not sure to understand your request. I might need to know more about your data and the logic you want to implement.
Can you elaborate more? What custom post types and custom fields are involved?
How is the view built? What posts are created updated by the form?

Any additional details will help understand your case better and advise you efficiently.

You might want to allow me temporary access to check your website closely. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1782453

Jamal
Supporter

Languages: Anglais (English ) Français (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Thank you Leila for these details, I understand you use case better.

You are currently looking for a way to create multiple visitors(posts) at once, right! When a visitor will be registered for every Monday, durant the month(let's say 4 Mondays), you want to create 4 visitor posts for the same person, keeping the same information(tel, name, etc...) and updating the Arrival date and time and the Departure date for the 4 Mondays, right?

First of all, note that a Toolset form is meant to create or edit only ONE post. To be able to create multiple posts, you will need to create custom code hooked to the cred_save_data action, that will create the additional posts.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

To pass data from the form to your action function, you can use generic fields.

Now, it is a matter of how you intend to do it. You may want to calculate the additional posts' arrival and departure dates/times on the frontend with Javascript, and pass them to the action function.
Or you may want to pass the rule(every week until a certain date) and calculate the date on the server end inside your action function.

Then you can create additional posts with the wp_insert_post function. https://developer.wordpress.org/reference/functions/wp_insert_post/
And update the post custom fields values with the update_post_meta function. https://developer.wordpress.org/reference/functions/update_post_meta/
Note that you will need to refix your fields with "wpcf-". Check the first section of this page https://toolset.com/documentation/customizing-sites-using-php/functions/

I hope this answers your question. Let me know if you have further questions.

#1787287

Great! Thanks for the information.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.