Skip Navigation

[Resolved] Associating a CRED commerce form with a parent post

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to connect child post with parent post using CRED

Solution:
You can use CRED hook: cred_save_data to connect child with parent.

You can find proposed solution, in this case, with the following reply
https://toolset.com/forums/topic/associating-a-cred-commerce-form-with-a-parent-post/#post-765319

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/cred-api/#csd
=> https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

This support ticket is created 6 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
- 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)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 6 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#764311

I am building a gift registry. The guests visit the registry and contribute to the registry.

Registry is a custom post type. Contribution is also a custom post type and is a child of Registry. Contribution has a CRED commerce form for the guests to fill with their contribution amount.

This is what I want: When the guests visit the registry and click on "contribute", the "Contribution" CRED commerce form should show up. I want the form to be able store the "registry's" post name or post ID, so that I can associate the contributions with the registries in a View.

Since the CRED forms are money related, I also want to pass the name/ID of the Registry to the Contribute form in a secure way.

My forms are working.

What I don't know is: how to create a new post for a "contribution" with a CRED form by clicking on the "registry" post, and have the "contribution" post inherit the "registry" post as its parent.

More generically: Click on a button in a post which opens a CRED form to create another post and make the latter the child of the former securely (without the user having to choose the parent in a dropdown).

My site is staging.mishkalo.com.

#765319

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand - you just wanted to link the parent post ID when creating child post.

You can use CRED hook: cred_save_data to connect child with parent.
=> https://toolset.com/documentation/user-guides/cred-api/#csd

To establish relationship between your parent and child 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

For example - 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', $parent_post_id);

I do not know how you are passing parent post ID to child post form. Following link may help you to understand how you can pass the parent post ID using url param.

More info:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/