Skip Navigation

[Closed] CRED to create type based on another type

This support ticket is created 3 years, 8 months ago. 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1732221

Hi, I have a pre-sales question (not related to my current toolset site)

Is the following setup possible in Toolset:

I have a customer who runs a smartphone repair shop. Per smartphone model, there are a number of possible repairs (e.g. display, home button, battery, etc.) We can create parent-child types for this.
When someone wants to book an appointment for a repair, he should be able to choose a smartphone model, and check the repairs that he wants. The checked repair children should consequently be linked (or copied?) to a new appointment type, which will hold other info such as name, email, date/time of the appointment, etc.
Is this possible? Can we have a CRED to create posts of a certain type, but based on the selected children of another type?
Thnx in advance for your reply!

#1733181

Hello, a single Form can only create or edit a single post, by design. However, with the Forms API you can trigger custom code when a Form is submitted. With custom PHP, you can programmatically create posts in any post type based on the User's selection(s) in the Form. We offer the cred_save_data API for triggering custom code when a Form is submitted: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
The User's Form field selections can be found in the $_POST superglobal inside your API callback function. There, you can use WordPress's wp_insert_post API to create a new post programmatically, based on those selected field values:
https://developer.wordpress.org/reference/functions/wp_insert_post/
You can use Toolset's Post Relationships API to establish a relationship between the post created by the Form and the new post(s) generated programmatically in your custom code:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

For a less automated approach that requires no custom code, you could use a Form to create the parent post type and let the User select the child post types they wish to associate with the parent post. Then when the Form is submitted, redirect the User to the parent post. In the parent post template, use conditionals to test the values of those child post type fields. Based on those values, show or hide links to create each of the child post types in separate Forms. When you use a Create Child Post Link from Forms, those child posts will be automatically associated with the parent post type.

Let me know if you have questions about those approaches.

The topic ‘[Closed] CRED to create type based on another type’ is closed to new replies.