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
- 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
denotes the specific form this code runs on and should be updated for your form.
is the name of the function you are calling the run when this hook is fired and as for the
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
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
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
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
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
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!!!