Skip Navigation

[Fermé] Gravity Forms Relationship Issue

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created Il y a 11 années et 9 mois. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 5 réponses, has 2 voix.

Last updated by Dave Il y a 11 années et 9 mois.

Assisted by: Caridad.

Auteur
Publications
#14764

I've been following the research and advice in these two posts:

https://toolset.com/forums/topic/how-to-code-post-relationships/
https://toolset.com/forums/topic/gravity-forms-and-relationships/

And besides not being able to sort out getting my parent id dynamically yet I've hit a problem with the update_post_meta functionality seen here:

update_post_meta($entry["post_id"], "_wpcf_belongs_item_id", "126");

Here I've manually entered an acceptable parent post of "126", now when I go into the child post and look at the bottom it shows the correct parent in the "Belongs to" drop down in the fields table. However, it will not appear on the list in the parents post until I click update on the child posts fields table!

Does anyone have any ideas what I can do?

#14832

Dear Dave,

Is item the slug of your parent post? If not, you need to replace item with it.

Regards,
Caridad

#14846

Hi Caridad,

I'm not 100% sure I follow what you're asking. The best thing I can understand from you question is if the '126' is the parent post slug, is that right? The parent post slug is /patient/TESTID but if I use that it doesn't even get as far as it did with the id.

However, it is my understanding of the function

update_post_meta

that the first parameter was the source, ie the id of the post being made as a child post. The second parameter was the database field to update, so in this case

_wpcf_belongs_item_id

and the third parameter was what to put in this database field, so in this case the id of the parent post as the function specifies belongs to ID not slug, so

126

should be correct.

Am I right about this or am I missing something, my php understanding is only average so it's entirely possible I'm being a bit dense, in case you haven't already here is the exact post I've got this code from:

https://toolset.com/forums/topic/gravity-forms-and-relationships/#post-8261

But as I said in my first post I'm sure I'm on the right lines as this code populates the correct parent in the child's table field drop down but it needs a manual click of the update button before it will add it to the parents field table list so I'm close just missing one little thing. Perhaps there is more than one field that requires updating for this to work correctly?

Thanks for getting back to me I really appreciate the help as as soon as I can crack this I feel I can really unlock the potential of my project 🙂

#14851

I've just figured it out!

I think you were right with what you were saying Caridad and I just didn't understand it. For anyone else reading this that doesn't quite get it I hope this explanation helps.

If you want to program a parent-child relationship using Gravity Forms then this is how to go about it and have it fill itself in correctly with Types.

add_action("gform_after_submission_3", "update_review_data", 10, 2);
function update_review_data($entry){
update_post_meta($entry['post_id'], '_wpcf_belongs_patient_id', '127');
}

Firstly you need to pass you're parent post id (if you know the title then you can use the WordPress function

get_page_by_title

- http://codex.wordpress.org/Function_Reference/get_page_by_title)

Either way you need to pass the parent post's specific post id to a hidden field and then begin to use the code I've posted here.

add_action("gform_after_submission_3", "update_review_data", 10, 2);

This line establishes the GForms hook, you need to use the gform_after_submission hook as this edit to the database takes place once the form data has been submitted but before the post back, redirection or whatever the confirmation function or the form is. The suffix

_3

denotes the specific form this code runs on and should be updated for your form.

update_review_data

is the name of the function you are calling the run when this hook is fired and as for the

10, 2

I know it's arguments but I honestly don't know what these do but most GForms have these numbers attached to various things so I'd just run with it.

function update_review_data($entry){

This code simply defines the function we called from the hook and passes it the

$entry

variable, which is a predefine variable that GForms stores all of the submitted form data in.

update_post_meta($entry['post_id'], '_wpcf_belongs_patient_id', '127');

Here we use the

update_post_meta

WordPress function (http://codex.wordpress.org/Function_Reference/update_post_meta) which allows us to change the submitted post data before it is committed to the database. This function is passed three parameters, the first is

$entry['post_id']

which is simply the ID of the post being created by this post submission, this code literally says "get the post ID stored in the variable $entry". The second parameter is

_wpcf_belongs_patient_id

and this is the database field that stores the parent type. This is the bit I struggled on for AGES before I saw it! You need to change the word patient to the name of you PARENT CUSTOM POST TYPE!!!

So, to reiterate, if you're parent custom post type is called House and the child custom post type is called Room, this snippet will read _wpcf_belongs_house_id

If you want to double check this name check the database field "wp_postmeta" and look in the column "meta_key" and somewhere in that column you will find the item _wpcf_belongs_YOURPARNETPOSTTYPENAME_id and it is this you need to enter.

In this example you can see I've entered the third parameter as

127

this is simply to test as this is the specific parent post I wanted to test it with, you can do the same to test this if you haven't got the hidden field populating correctly yet, other wise this would be the GForms field id of you hidden field entered like this:

update_post_meta($entry['post_id'], '_wpcf_belongs_patient_id', $entry[6]);

So the field ID of the hidden GForms field with the parent post ID is 6 in this example.

That's it! This is how I got this to work and I can now program the post relationships correctly and fully interface GForms with Types.

I hope this break down has helped others as I found it a pain to dig through this and make it work.

Caridad, thanks you your post it gave me the clue I needed to crack this and I once you guys have confirmed what I've said here is accurate post back and I'll set the issue to resolved.

Thanks again!!!

#14852

Dear Dave,

Yes, its correct. Thank you for the explanation. Im sure other user will find it useful.

Regards,
Caridad

#14857

Many thanks Caridad, your help desk service is brilliant, I've never had a reply on most of these forums.

Either way the issue has been marked as resolved and I hope others find this useful!

Le sujet ‘[Fermé] Gravity Forms Relationship Issue’ est fermé à de nouvelles réponses.