For some reason this page has 2 layouts assigned to it.
This layout enlace oculto
As well as this one . enlace oculto
However the one that seems to be loading is this. enlace oculto
Ok so the Content Layout for this page enlace oculto
There is also a layout assigned to the page. That is why it is happening, however on the assigned layout you are not loading the page content itself but rather a layout with another form.
This is why the form with ID 1787 isn't loaded on the page, that is this layout here enlace oculto
If you were to remove the layout assignment from the page enlace oculto
You should get the 1787 layout loading. For this page this is the reason why a different form is being loaded that the one you thought it will be .
Initially you gave me a url like this. enlace oculto
This means there is a child_post_id variable in the url. Assuming you code gets the ID from the url and then makes the changes based on this url.
What I would like to know is the post type that has a post with the id 4845 or which CPT is it in.
Thats because your code is meant to modify that post. Or could you let me know which post is the People post type suppose to be related to because there isn't a Types post relationship attached to the People CPT.
1. We are on the layout page for a single CPT 'Person' enlace oculto
On this page (Through the view id: 2599) we select the option to 'Create NEW Guardian' - This will take us to the second page sending the id of person-1 in the url (?child_post_id=4845)
2. We are now taken to the 'add-guardian' page which picks up person-1 id. On this page we create a new CPT 'Person' (person-2) using the form ID: 1787 and the function hook below should make the new person-2 the parent of person-1 and also change the CPT field 'Guardian' to 'Yes'
add_action('cred_save_data','func_update_parent_field',10,2);
function func_update_parent_field($post_id,$form_data) {
if ($form_data['id']==1787) {
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']);
}
}
This form relates to the new CPT Person aka The Parent so the Adopted field should say No... but the hook should make the Adopted field for the child ‘Yes’
Best wishes
Geoff
Where you have $_POST['wpcf-adopted'], this is getting the value from the field on the frontend, which says "No". Is it that you want to default it YES ?
Please let me know under what scenario would this be a Yes so we can make some changes to the code.
This page (add-guardian) creates a new CPT 'Person' that becomes the parent. The child (passed by ID in url) was created with the default 'No' for the Adopted field hence why it says No... at this point of submitting the form on this page I need the child (passed by ID in url) field for Adopted to change to 'Yes'