Sauter la navigation

[Résolu] Create child post from CRED

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

The issue here is that the user wanted to create his child post immediately after creating the parent and also having that child post automatically assigned to the created parent.

Solution:
You can achieve the redirect and the automatic parent assignment by using the hook below.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

Using this format

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==12)
        return 'urltochildform?parent_{CPTSLUG}_id='.$post_id;
    return $url;
}

You will need to add the child form to a different page and using the redirect hook above to redirect to that page.

This support ticket is created Il y a 6 années et 9 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Ce sujet contient 4 réponses, a 2 voix.

Dernière mise à jour par rafaelL-2 Il y a 6 années et 9 mois.

Assisté par: Shane.

Auteur
Publications
#628709

Tell us what you are trying to do?

NOTE: I am using the latest beta of types, views, etc.

I have a Parent custom post called "patient" their childs are "medical-consultation" So the relationship are one to many (One patient can have one or more "medical-consultation"

I want to create a CRED form with the hability to submit a parent post and their first child. Example:

1-Credform --> user populate the data using CRED, in the form will see the fields relating the Parent post we are going to create, and also the fields related to the first child post (medical-consultation) we are going to create.

2-When user submit the form will happen two things:
2-1 We will have new patient custom post type
2-2 and also a medical-consultation post type connected to that patient.

Is that possible with CRED?

#628829

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Rafael,

Thank you for contacting our support forum.

Unfortunately no this is not possible.

The issue is that the parent post will need to be created first so we know what the ID is to attach to the child post. So its not possible to create the 2 at the same time.

Thanks,
Shane

#628849

Hi Shane

OK, I assumed that. So I still need the following.

1-I have a CRED form who submits Parent custom post called "patient". After that user must be redirected/forced to create their child custom post "medical-consultation", so I will redirect to cred form of that child post. After submit, that child post must be linked to their parent automatically.

The user flow will be like:

a-Cred Form of "Patient", user submits data
b-Cred Form of "medical-consultation", user submits data and that post is a related (automatically) to the patiend previous post.

Could you help me with this please?

Regards

#629406

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Rafael,

You can achieve the redirect and the automatic parent assignment by using the hook below.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

Using this format

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==12)
        return 'urltochildform?parent_{CPTSLUG}_id='.$post_id;
    return $url;
}

Please try this and let me know if it helps.
Thanks,
Shane

#630760

Thanks. I will try that way