Skip Navigation

[Gelöst] Ability to create new child posts during the creation of a parent post in CRED

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

Solution:
You can use CRED API hook cred_save_data in order to create child post and to establish relationship (connection) between your parent and child post type entry you need to add postmeta key.

When using Types posts relationships, the parent of a given type is stored in a field:

_wpcf_belongs_{parent-posttype-slug}_id

You can find proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/ability-to-create-new-child-posts-during-the-creation-of-a-parent-post-in-cred/#post-609624

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/creating-post-type-relationships/
=> https://toolset.com/documentation/user-guides/cred-api/#csd

This support ticket is created vor 6 Jahren, 10 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von larryB-3 vor 6 Jahren, 10 Monaten.

Assistiert von: Minesh.

Author
Artikel
#609547

Tell us what you are trying to do?
I have a parent post type called "Facility Report" that basically only has a couple of fields. I also have numerous child post types for that parent that a user could choose to create when completing a Facility Report. I'm looking to create a front-end form using CRED where a user starts a new Facility Report, completes a couple of data fields and is then presented sections on the form for each of the child post types, for example "landscaping", "gates", and "clubhouse". The user should be able to click on something, maybe a "+" and complete the couple of fields associated with that child post type as necessary. Repeating with the other children sections also. When all done, the main parent post type of Facility Report is then created and when viewed you could see the parent fields and the child post fields that were completed.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#609624

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - you can use CRED API hook cred_save_data in order to create child post.

Considering that you have created parent/child relationship using Types:
=> https://toolset.com/documentation/user-guides/creating-post-type-relationships/

Now, you can use CRED hook: cred_save_data to manipulate your data and create child post
=> https://toolset.com/documentation/user-guides/cred-api/#csd

Using above hook you can create child entry using the WordPress function - wp_insert_post:
=> https://developer.wordpress.org/reference/functions/wp_insert_post/

To establish relationship (connection) between your parent and child post type entry you need to add postmeta key. When using Types posts relationships, the parent of a given type is stored in a field:

_wpcf_belongs_{parent-posttype-slug}_id

Let’s assume that we are displaying a Car post type that has a Maker as a parent post type.
Each Car will store its Maker (parent) id in the field _wpcf_belongs_maker_id.

update_post_meta($child_post_id, '_wpcf_belongs_maker_id', $post_id);

Please check following related ticket that may help you:
=> https://toolset.com/forums/topic/automatic-post-creation-on-registration/#post-555243

#609950

Thank you.