Sauter la navigation

[Résolu] How to update child post value from parent post

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

Problem:
How to update child post value from parent post

Solution:
You can use Toolset Forms (CRED) hook "cred_save_data" to set child post value.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/continuation-from-previous-ticket/#post-1122659

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created Il y a 6 années et 3 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Marqué : 

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

Dernière mise à jour par geoffD Il y a 6 années et 3 mois.

Assisté par: Minesh.

Auteur
Publications
#1121712
Screen Shot 2018-10-05 at 20.36.55.png

Hi Minesh

I've opened a new ticket as the last one I closed, however there is one last thing I need to do...

I need the custom field 'Adopted' of the CHILD whose child post ID you pass in the URL to become 'Yes' when the new PARENT is created.

I'm happy for you to use the same login details as before...

I really appreciate your help...I'm also learning at the same time!

I have added a screenshot from your notes from the previous post in case you don't remember:

Many thanks

Geoff

#1122617

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes - I understand the code but when you mean by you need the custom field of the child post.

Do you mean that you want to save "Adopted" field value to parent post or child post?
If it's child post - its not saved?

#1122653

Hi Minesh

Hope you've had a great weekend!

Yes that's what I mean..As the spy being saved at the time is the new PARENT I also need the CHILD custom field 'Adopted' to be filled and saved with 'Yes'... At the moment we just pass the CHILD ID..

Many thanks as always

Geoff

#1122659

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Well - I've updated the code in functions.php file as given under.

add_action('cred_save_data','func_update_parent_field',10,2);
function func_update_parent_field($post_id,$form_data) {    
		if ($form_data['id']==2613) {       
				wp_update_post(array('ID' => $_REQUEST['child_post_id'],         'post_parent' => $post_id    ));    
				update_post_meta($_REQUEST['child_post_id'],'wpcf-adopted',$_POST['wpcf-adopted']);
		}
}

Could you please confirm it works as expected.

#1122760

My issue is resolved now. Thank you Minesh!!!