Skip Navigation

[Resolved] Custom Field for Relationship using Gravity Forms Post Creation

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

Problem:

A user reported that he is trying to use "toolset_connect_posts" function in a function attached to Gravity Form's hook to connect two posts in a relationship, but it doesn't seem to work.

Solution:

During troubleshooting, it emerged that the correct relationship slug needed to be used.

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

This support ticket is created 2 years, 9 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 7 replies, has 2 voices.

Last updated by joseM-8 2 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2327319

Tell us what you are trying to do?

i am using Gravity Forms Post Creation to create a child post but can't get them to connect to parent.

Is there any documentation that you are following?
https://toolset.com/forums/topic/custom-field-for-relationship-using-gravity-forms-post-creation/

here is the code i used.
// Growth indicator to Company Relationship From GF Form Submit
add_filter( 'gform_advancedpostcreation_post_after_creation_6', 'apc_toolset_setparent', 10, 4 );

function apc_toolset_setparent( $post_id, $feed, $entry, $form ) {

toolset_connect_posts( 'customer-cut-order', $entry[9], $post_id );

}

Is there a similar example that we can see?

What is the link to your site?
hidden link

#2328421

Hi,

Thank you for contacting us and I'd be happy to assist.

I've checked the form link that you shared and noticed that the field "Parent_post" is empty. Can you please test if the code for the relationship works, if you fill the value "600" in that field and then submit the form?

If it works, it would mean that the custom code is working as expected and you'll just need to pre-fill the value in the "Parent_post" field from the URL parameter "parent_post".
( ref: hidden link )

regards,
Waqar

#2328425

Sorry I made changes to my page. Here is the correct address

hidden link

Still not working.

#2328513

Thanks for writing back.

To troubleshoot this, I'll need to see how this relationship and the form are set up in the admin area.

Can you please share temporary admin login details, in reply to this message? I'll also need your permission to download a clone/snapshot of the website, in case it needs to be investigated on a different server.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

#2329269

The user access details work, but this user doesn't seem to have the "administrator" role.

Please change the role of this user to "administrator", so that I can access the website's important sections and settings.

#2329651

sorry that was my fault. I have updated the user permission.

#2329893

Thank you for enabling the admin access.

I noticed that the relationship slug used on your website is "company-growth-indicator-set", but in the custom code "customer-cut-order" is being used.

Please replace it with the correct slug and it should work:


// Growth indicator to Company Relationship From GF Form Submit
add_filter( 'gform_advancedpostcreation_post_after_creation_6', 'apc_toolset_setparent', 10, 4 );
 
function apc_toolset_setparent( $post_id, $feed, $entry, $form ) {
	toolset_connect_posts( 'company-growth-indicator-set', $entry[9], $post_id );
}

Note: The example link that you shared uses the value "600" for the URL parameter "c_nameid". But there is no "Company" post with the ID '600' on the website. Please make sure that in the URL parameter, you use the ID of a correct and existing company post.

#2330163

My issue is resolved now. Thank you!