Save form to Custom Post type with relationship

I have a form that upon submission I want it to populate my custom post types and respect the relationships.

For example, I have properties and appliances. It is a one to many relationship. One property can have more than one appliance. I want the user to enter the property address. If the property does not exist then I want to create the property given the address. Next I want to relate the appliance data to the property. If the property does exist then I want to just relate the appliance data to the property. I have this all setup with Custom Post Types and custom fields on Wordpress. I am not entirely sure how to connect the two.

Thanks.

Hi Chris,

Can you describe if/what plugin(s) you have used to define your custom post types, custom fields, and the one-to-many relationship? Or just that you’ve registered the CPT with register_post_type and think of them as one-to-many but nothing in the database to reflect that as such?

The Advanced Post Creation add-on supports creating both posts, pages and CPT’s. Different meta box plugins such as Advanced Custom Fields, Custom Post Types UI or CMB2 each have a different approach, but generally speaking you’d be defining some type of post meta data that associates appliance to property. If you can identify that, using the APC add-on to define the values should be pretty straight forward.

If your scenarios need to leverage values from one generated CPT into a subsequent one to be created (or store them back into the form entry as hidden or administrative fields), you may want to look how easy it would be with Gravity Flow. Our no/low code approach to defining steps in a workflow that can feel like separate branches would feel as simple as setting up conditional logic to show/hide fields on the form. From how you describe the difference between property existing (or not) and potential for multiple appliances per property within one form, Gravity Flow could make your setup possible in a matter of minutes once you know the meta field details to map.

Cheers,
Jamie

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.