[Résolu] Custom Field for Relationship using Gravity Forms Post Creation
Ce fil est résolu. Voici une description du problème et la solution proposée.
Problem:
The user is using Gravity form and the "Post Creation" addon to create some custom post type. He would like to link the created post with a parent post that is collected from a Gravity form field.
Solution:
You will need to hook into the gravity form submit process and use the toolset_connect_posts function to link the posts with the Toolset relationship.
The user ended up using this custom code:
// Customer to Cut Sheet Relationship From GF Form Submit
add_filter( 'gform_advancedpostcreation_post_after_creation_4', 'apc_toolset_setparent', 10, 4 );
function apc_toolset_setparent( $post_id, $feed, $entry, $form ) {
toolset_connect_posts( 'customer-cut-order', $entry[21], $post_id );
}
// Customer to Cut Sheet Relationship From GF Form Submit
This support ticket is created Il y a 3 années et 6 mois. 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.
I need to know which custom field (if any) connects a CPT (Cut Sheet) to its parent (Customer), when the post is created with Gravity Forms Post Creation.
it used to be _wpcf_belongs_customer_id, but that doesn't seem to work.
Hello and thank you for contacting the Toolset support.
I am not familiar with the Gravity Forms Post Creation plugin or the Cut Sheet and Customer elements. I looked online for any references to no avail.
Can you elaborate more on your questions? What would you try to do?
Are "Customer" and "Cut Sheet" custom post types created with Toolset? Are they connected using a Toolset relationship?
Please provide as many details as possible, so we can understand your request and your website setup quickly and advise you accordingly.
Hey Jamal,
"Customer" is a CPT. "Cut Sheet" is another CPT. "Customers" are single parents of many "Cut Sheets." "Post Creation" is a Gravity Forms add-on. It creates a post (Cut Sheet) when a user submits the form. The "Customer" post ID is passed in the URL that takes a user to the form. I need that "Cut Sheet" to belong to a "Customer."
The form contains a field, "Belongs To Customer," that's automatically populated with the Customer ID, when they get to the form. I need to pass that Customer ID to a custom field, so the new Cut Sheet will be connected with that specific Customer.
This is for a deer processing and taxidermy business. I hope that helps.
You will need to use this function, either inside a hook from the Gravity Forms. Check this article hidden link
Or inside a "post_save" hook from WordPress.
Because currently, Toolset does not related anymore on a custom field to store the relationship between posts. It is now managed by some extra database tables that Toolset Types manage.
I hope this answers your question. Let me know if you still need any information.
Yes, the relationship is one-to-many. One Customer has many Cut Sheets. Only the business owner will have access to this website. They will be entering all the information, for each Customer who comes in and each Cut Sheet to be created.
As soon as you mention "hook" I'm out. I can place code where it needs to be placed, but beyond that, I'm useless.
For instance, in "add_action( 'gform_advancedpostcreation_post_after_creation_1', 'your_function_name', 10, 4 );" I can guarantee "your_function_name" means more to you, than me.
Is it possible for you to tell me what to add to my functions.php file, to get this working? In my head, it should only be about 5 lines, max. Again, I know nothing.
// $entry stores your passed values where the ID of the array is the field value
// if you stored your 'parent record' in a hidden field with an id of 7, you'd use
// $entry[7] to retrieve that value. You can use that ID below in the areas where you need it, ie post meta and
// $post_id_of_post_to_relate_to
// Run Toolset Update Post Reference
// I believe $post_id_of_post_where_prf_is_saved can be replaced with $post_id as that is the record just saved
toolset_connect_posts( 'prf_slug', $post_id_of_post_to_relate_to, $post_id_of_post_where_prf_is_saved );
// Replace my_custom_field_key with your custom field meta key.
update_post_meta( $post_id, 'my_custom_field_key', $entry[7] );
}
******
Also, they don't have a license for Toolset, so they weren't exactly sure of the way this needs to be done and I can't believe they don't have a license for Toolset. Maybe you should give them one?
The toolset_connect_posts acepts three arguments:
- The relationship slug, from the Gravity forms support reply, I would say it is "prf_slug", but you will have to go check in the relationship page what is the slug. Check this example hidden link
- The parent post ID. Gravity forms Support has explained that it depends on when you have put it on the form. They suggested the example $entry[7], if it is the 7th field in the form.
- The child's post ID. As the form is for creating Cut Sheet, the post ID is $post_id.
The could should be then:
I am only sure of "$post_id", you will have to check if $entry[7] does hold the Customer ID, and make correct the relationship slug if it is no "prf_slug".
The form You find on each custom post like hidden link
Where customers can leave a review (they should be logged in).
Having there 2 hidden fields, one with the "parent" ID.
In toolset my Gym ID from the review custom post type is as single line defined. This should "connect" then the post ID from each Gym. As each Gym are the parent and the reviews the child.
Any tip i can check?
Regards,
Simon
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.