Thx a lot. I've tried the following, but the form now hangs after submission and does not proceed to the payment options?
/**
* Connect dog and contact posts to the intermediate post created by the form
*/
add_action('cred_save_data', 'ts_connect_to_intermediate', 10, 2);
function ts_connect_to_intermediate($post_id, $form_data)
{
// Edit the form ID ( 123 in the example below )
if (in_array($form_data['id'], array(210832))) {
// Edit the slug of the generic field included in the form which contains the ID of the dog
// that will be available in the $_POST object ( 'dog_id' in the example below )
$dog_id = $_POST['dog_id'];
// Retrieves contact post of current user
$contacts = get_posts( array(
'post_type' => 'contact',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'limit' => 1
) );
$contact_id = $contacts[0]->ID;
// Edit slug of relationship between dogs and contacts ( 'sponsorship' in example below )
ts_connect_existing( "doctor-sponsorship", $contact_id, $dog_id, $post_id );
}
}
If the form hangs then it sounds like a fatal error. I don't see any syntax errors that would cause that, so I'm wondering if you left the code that defined the ts_connect_existing function in place (not shown above) or if you deleted it.
If you deleted it then you would get a fatal PHP error when calling a non-existent function.
You can verify that by checking your debug logs.
If you haven't already, turn on the debug log by editing your wp-config.php file and change the line with WP_DEBUG like so:
That will create a debug.log file in your /wp-content/ directory which you can examine in any text editor. Try submitting the form again and then inspect the log.
Otherwise I would double-check that "contact" is the slug of your contact post_type, and lastly, double-check that you have the contact_id and dog_id in the right order in the final line (the same order as in the relationship itself, with contact_id the left hand side of the relationship and dog_id the right hand side).
(I can't check myself because when I log in to your site I can't access the backend.)
Thx Nigel, this was very clear and helped me solve it. I really did miss the additional code, sorry about that 🙂 and the order was different between dog_id and contact_id. It WORKS NOW! Thank you very much and for the future I have set your login to administrator so you should be able to log in the next time you help me 🙂 Thx a lot, great job!! I'll be back with more questions soon 🙂
Absolutely, let‘s close this and see each other back with another question 🙂 thx again for your great support, I am very excited to develop the functionality of the website further now. The dogs and all of our charity are thanking you. Cheers. T