Skip Navigation

[Resolved] How do I create 2 child records from a new parent record using the API?

This support ticket is created 6 years, 11 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.

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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by simonC-4 6 years, 11 months ago.

Assisted by: Noman.

Author
Posts
#525676

Hi,
I am collecting details about an order (Custom Toolset Type) and collecting 2 peoples names on that form. What I'd like to do on successful save is: a) Create 2 new People (Custom Type) posts and b) join them to the order by creating a child Order Person post (m-2-m join post type).
I'm sure this is possible however can't seem to find an example, please could you help me out?
Many thanks in advance,
Si

#525703

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thank you for getting in touch with us.

1. Using cred_submit_complete action hook we can create posts.
https://toolset.com/documentation/programmer-reference/cred-api/#csc

If this post needs to be parent post. You can pass this variable to child post post_parent args.
$post_id

2. In above action hook function you can create 2 posts using wp_insert_post function.
https://developer.wordpress.org/reference/functions/wp_insert_post/

3. You need to define 'post_parent' argument in wp_insert_post function when insert post.

Please let me know if you have any question regarding this.
Thank you

#525722

Many thanks Noman. I can create the post however I cannot seem to set my custom type fields. I tried with the same name as used by cred_field as well as prefixing it with 'wpcf-' but it doesn't seem to work. Any ideas please?
Si

#525770

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Simon,

Types is using a custom field "_wpcf_belongs_{parent-post-type-slug}_id" to store parent post ID, for example:
- parent post type = edition
-- child post type = article

In each child (article) post, there is a custom field "_wpcf_belongs_edition_id", the field value is parent (edition) post ID.

You can create some custom function to setup the custom field, with WordPress function update_post_meta():
https://codex.wordpress.org/Function_Reference/update_post_meta

Further, as this is a custom requirement it would need some custom coding to make it work. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

Thank you

#525788

Thanks Noman, it works using the update_post_meta()!
Si

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