Home › Toolset Professional Support › [Resolved] WordPress hierarchy in custom posts
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)
Tagged: Content-submission forms, Toolset Forms
Related documentation:
This topic contains 75 replies, has 2 voices.
Last updated by Shane 5 years, 5 months ago.
Assisted by: Shane.
Hi Geoff,
For some reason this page has 2 layouts assigned to it.
This layout
hidden link
As well as this one .
hidden link
However the one that seems to be loading is this.
hidden link
Ok so the Content Layout for this page
hidden link
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
hidden link
If you were to remove the layout assignment from the page
hidden link
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 .
See my screenshots.
Please let me know if this helps.
Thanks,
Shane
Hi Shane
I think for the page 'add-guardian' I now only have one layout assigned 'People New Guardian' (ID:2612) - Can you check this please.
But now the parent/child function does not work.
In template 2612 I use the form with ID: 1787 and the corresponding hook I have simplified for testing purposes to:
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']); } }
So not sure why this doesn't work now?
Thanks for your continued help and support
Best wishes
Geoff
Hi Geoff,
The good thing is that the hook actually fires off because i modified it with a die() function and it works.
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) { die('this works'); } }
See screenshot for verification.
I'm tracing through, could you let me know the link of the post with the id 4845
Thanks,
Shane
Hi Shane
I'm not too sure what you mean....
Here is the url to the view (2599) where the user links to the add-guardian page
hidden link
The link is here in the loop:
hidden link;">Create NEW Guardian
If you mean the URL to the CPT 'Person' with id 4845 it is here:
hidden link
Speak soon
Best regards
Geoff
Hi Geoff,
Let me try and clarify.
Initially you gave me a url like this.
hidden link
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.
thanks,
Shane
Hi Shane
Ok..so we have 2 stages:
1. We are on the layout page for a single CPT 'Person'
hidden link
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']); } }
Hope this makes sense...
Regards
Geoff
Hi Geoff,
I reformatted the code and it is now work.
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']); } }
If you go to the post here
hidden link
You will notice that the parent information is now set as intended, as well as the custom field being updated.
Thanks,
Shane
Hi Shane
I can see that the parent/child part is working but it doesn't seem to change the 'Adopted' field of the child to 'Yes'
Best wishes....and thank you
Geoff
Hi Geoff,
It is actually correct. If you check the form here you will notice that the field for adopted says no.
hidden link
See Screenshot.
Thanks,
Shane
Hi Shane
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
Hi Geoff,
Thanks for the clarity, however this line of code says otherwise.
update_post_meta($_REQUEST['child_post_id'],'wpcf-adopted',$_POST['wpcf-adopted']);
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.
Thanks,
Shane
Ah Ok I understand now...
The result I want is for the field 'Adopted' :
Parent : No
Child: Yes
Is this possible?
Regards
Geoff
Hi Geoff,
Ok i understand, yes it is possible to do.
However in this example here
hidden link
It is not since the child field says no.
So we know it works to set the adopted to No. Are you able to send me a link to one where the field would default to yes ?
A different use case will allow me to adapt the code.
Thanks,
Shane
Hi Shane
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'
Hope this makes sense
Regards
Geoff
Hi Geoff,
I get what you mean now, Then we can default it to a yes then.
Modify the line with this.
update_post_meta($_REQUEST['child_post_id'],'wpcf-adopted','Yes');
Thanks,
Shane