Skip Navigation

[Resolved] Adding Post Relationships to a CRED form

This support ticket is created 7 years, 5 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 7 years, 5 months ago.

Assisted by: Beda.

Author
Posts
#528967

On my clients website that we are building in a sandbox, I have set up a many to many relationship using an intermediary custom post type. We are

using Woocommerce and the products are Machines. The two CPTs are Companies and Ownership (the intermediary post type).

(fyi but not relevant: we have injected the company and contact post types with the WooCommerce product taxonomy using code in the functions

file)

We have built 3 CRED forms, one each to add a new Machine, a new Company and a new Contact.

The Company CPT has 2 children: Ownership and Contact. The Contacts are easy: when I use the auto-generate function in CRED, it automatically adds

the drop-down to select the Company with whom the contact is associated.

In the CRED to add a Machine, even though the relationship is established in the custom post type, I cannot get the CRED to show a drop down of the

companies on the form. If I edit the Product (Machine) directly in the WordPress dashboard, I can see the post relationship and select the company

(after saving the Product first). When I manually copy the code from the ownership custom post type, I get a CRED error.

<div class="form-group">
		<label>Machine Owner</label>
		[cred_field field='_wpcf_belongs_product_id' value='' class='form-control' output='bootstrap']
	</div>
	<div class="form-group">
		<label>Machine Owner</label>
		[cred_field field='_wpcf_belongs_pm-company_id' value='' class='form-control' output='bootstrap']
	</div>

Is this because the product has to be saved before the post relationship can be established?

Here are my CRED forms:

The "add a Contact" form is here:
hidden link
at the bottom of the form, you can see the option to associate the contact (child) with its parent (company). This is wonderful.

MY QUESTION:
On the "add a machine" form:
hidden link
I would like to add the drop-down to associate that machine with a Company.

How do I do that, please?

#529148

Basically, with CRED you can choose a Parent when creating a Child (or more than one parent)

This works fine, but the Parent Posts must be first existing, of course, for them to be chosen.

They must be published as well (cannot be drafts).

Then the Parent Post Picker works fine.

What you cannot do is create a Parent Post from within a Child Post Form.

Your process would be:
1. Create all Parent Posts first
2. Then, from either within the Parent Post add a Child post Form Link, or insert the Parent Picker in a Child Post Form.