I am trying to copy post data to a parent post if a generic field checkbox is checked. For some reason it's not working and I can't figure out why.
I based my solution partially on this article. https://toolset.com/forums/topic/update-parent-with-child-info/
I have two post types: HR Profile and Job Application. The post types are connected with a relationship hr-profile-job-app.
I have a form #5006 which is for editing a Job Application. This form has a Cred_generic_field copy-data-to-hr-profile which is a checkbox.
[cred_generic_field type='checkbox' field='copy-data-to-hr-profile']
{
"required":0,
"default":"",
"label":"Check to copy Job Application data to the HR Profile."
}
[/cred_generic_field]
This form also has a Cred field last-name
[cred_field field="last-name" force_type="field" class="form-control" output="bootstrap"]
I crafted the following code to copy the field value to the parent if the checkbox is checked. It's not working.
// COPY JOB APPLICATION FIELDS TO HR PROFILE
function job_app_data_action($post_id, $form_data) {
$update_trigger = $_POST ["copy-data-to-hr-profile"];
// IF ITS THE RIGHT FORM AND THE UPDATE CHECKBOX IS CHECKED
if (($form_data['id']==5006)&&($update_trigger==1)) {
$parent_hr_profile_id = toolset_get_related_post( $post_id, 'hr-profile-job-app', 'parent' );
$update_last_name = get_post_meta($post_id, 'wpcf-last-name', true);
update_post_meta($parent_hr_profile_id, 'wpcf-last-name', $update_last_name);
}
}
add_action('cred_save_data', 'job_app_data_action',10,2);