Skip Navigation

[Resolved] Select CPT relationship within Gravity Forms post submission

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.

This topic contains 2 replies, has 2 voices.

Last updated by Alex Telloyan 2 years ago.

Author
Posts
#2541397

Tell us what you are trying to do?

I am programming a GravityForm geolocation submission form to get custom coordinates for a database. This form will create a CPT called System. The goal is to have an option within this form to select/connect a different CPT within a relationship called Address. Each address can have multiple Systems.

I don't see that I can utilize custom fields to make this work, so I'm at a loss of what to try next.

Is there any documentation that you are following?

I have briefly reviewed https://toolset.com/forums/topic/gravity-forms-and-post-relationships/, but am not exactly sure what else I can do.

#2541779

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

It sounds like you have a one-to-many relationship between Address posts (parent) and System posts (child), and you have a form to publish child posts where you want to link the child System post to a parent Address.

(Read about post relationships here: https://toolset.com/course-lesson/what-are-post-relationships-and-how-they-work/)

You can include parent fields in Toolset Forms and this is handled automatically, but if you are using Gravity Forms you will need to do it manually.

Your form will need to include a dynamic field from which users can select an address. (If this is a select field, you will want the options to have the address post id as the option value, and the address post title as the label.)

Then, use a hook to run code after the form is submitted (check the Gravity Forms documentation for what they have available). You should have available the ID of the new System post and the ID of the Address post selected in the form, and you can use those to connect the child to the parent using the API function toolset_connect_posts (https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts).

If you are unable to do this, you should be able to find a Toolset contractor who could do this for you: https://toolset.com/contractors/

#2542877

You are right on our database structure, and the information you provided has been most helpful. Thank you for your assistance!