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 );
}
}
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
The code looks pretty much correct.
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:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DISABLE_FATAL_ERROR_HANDLER',true);
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 🙂
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Great, I'm really pleased, because it required quite a bit of thought 🙂
I think we can probably close this and you can ask any more questions in new threads (you can assign to me or ask for me to be assigned if you like).
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