Skip Navigation

[Resolved] WordPress hierarchy in custom posts

This support ticket is created 5 years, 6 months ago. 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)

This topic contains 75 replies, has 2 voices.

Last updated by Shane 5 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#1244249

Hi Shane

I think that's done the trick!

I can now create the parent/child relationship on multiple forms and not occur any page duplication..

I'm going to just run some more tests before I close the ticket...but thank you so much for your help!

best regards

Geoff

#1244255

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

Happy i'm able to help you get through this and understand the issues thus far 🙂

Looking forward to hearing your test results.

Thanks,
Shane

#1256215

Hi Shane
Apologies for not being in touch..I've had issues with my site being hacked so have had to restore from a backup and re-install plugins etc..

So it looks like I still have a problem with the WordPress Parent/Child system:

On page:
legacyangel.com/guardians

I have a list of CPT 'People' that are all children(with custom field CHILD = 'Yes') and next to the child's name I have a link to that persons layout:
legacyangel.com/person/child-1

On that layout there is a list (ID:2599) of potential parents (these are all CPT 'People' again with custom field GUARDIAN='Yes') and next to the potential parent is a link that takes you to the layout 'people add guardian' - ID 2573 and on this layout is an edit form (ID:2574) for the child on the previous page. Also on this form it takes the ID that has been passed in the URL of the potential guardian and adds it an the Childs parent...then when submitted it redirects back to legacyangel.com/guardians page.

This part all works fine and can be repeated over and over again with any of the potential guardians in the list...

Here's the problem:

On the child's layout page
legacyangel.com/person/child-1
there is also an option (as you know from previous discussion) to create a new CPT 'Person' who becomes the child's Parent. When selected 'Create New Guardian' it takes you to a page using the layout ID:2612 - 'people new guardian' on this page is the form id:1787 ('create-new-guardian') that sets up a new CPT person and using the hook we created:

[code]
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 or $form_data['id'] == 4033 or $form_data['id'] == 4049) {
wp_update_post(
array(
'ID' => $_REQUEST['child_post_id'],
'post_parent' => $post_id
)
);
update_post_meta($_REQUEST['child_post_id'],'wpcf-adopted','Yes');
[/code]

makes the new Person a parent of the child passed in the URL and turns the custom field 'Adopted' of the child to - 'Yes'... This all works fine now and redirects correctly back to :
legacyangel.com/guardians

However now when I select a child to edit in View ID:2548 on this page using the code as before:

[code]
[types field="person-full-name"][/types] [wpv-conditional if="( $(wpcf-adopted) eq 'Yes' )"]- Guardian: [types field='person-full-name' id='$parent'][/types][/wpv-conditional] Choose/Change Parent....
[/code]

It takes me to the newly created CPT Parent template rather than the selected child in the list..

I know this is long-winded but hopefully makes sense..

Esentially I always want to view the child when a person is selected in the template for people page...

So to show you how I created this problem here are the 3 scenarios all starting from the legacyangel.com/guardians page:

1. Selected child and it took me to:
legacyangel.com/person/child-1
Then chose a potential guardian from list in view ID:2599 which took me to child edit page where the potential guardian was added as the Childs parent - then was redirected back to guardians page which showed that the child had been adopted.

2. I then followed process 1 above to choose a new potential guardian from the list in view ID:2599 and when I select the child here it took me to:
legacyangel.com/person/parent-1/child-1
Again when selecting a potential guardian it adds them as the Childs parent and redirects to the guardians page - and I can repeat this process over and over again..

3. I select a child as in steps 1 and 2 but this time on the person template instead of selecting a potential guardian from the list in view ID:2599 I select 'Create New Guardian' taking me to layout ID:2612 which using form ID1787 and the hook we created creates the New CPT Person, makes them parent of the selected child and then redirects to the guardians page ok.

4. THIS IS THE PROBLEM - now after creating a new CPT above as the guardian, when I select a child from the list in view ID:2548 it takes me to their parents layout page (i.e. the new Person we created in step 3) rather than the child in the list..

I shall look forward to hearing from you...If we can get this sorted then I think I'm almost there!!

Best regards

Geoff

#1261403

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

I believe i'm following but would it be possible to get an account where there is a list of guardians and children already tied to the account ?
hidden link

On my user account its all blank.

Setting up an admin account with the issue already there would help me a whole lot to pinpoint the exact issue.

Thanks,
Shane

#1261547

Hi Shane

Good to have you back...have you been on holiday?

I have now set up CHILD 1 and CHILD 2 and POTENTIAL GUARDIAN 1, POTENTIAL GUARDIAN 2 and POTENTIAL GUARDIAN 3

When you have logged in, If you go to the page:
hidden link
You can select which child to choose a guardian for....which when selected will take you to the PERSON layout for that child where you can either select an existing potential guardian(1,2 or 3) or Create a new one (which is where the issues start!)

Hope this all makes sense...let me know if you have any issues..

Best wishes

Geoff

#1264705

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2019-06-10 at 4.33.48 PM.png

Hi Geoff,

I like when we handle the issue one step at a time it makes things very clear.

So now i'm at this page hidden link

Do I click to add a new parent ?

#1265041

Hi Shane

So yes lets follow the steps one by one:

1. Selected child and it took me to:
legacyangel.com/person/child-1
Then chose a potential guardian from list in view ID:2599 which took me to child edit page where the potential guardian was added as the Childs parent - then was redirected back to guardians page which showed that the child had been adopted.

So it looks like you're on the guardians page that lists all of the children that need to find parents.. from this click on 'Choose/Change Parent' from CHILD 2 - this will take you to the layout for "PEOPLE' and specifically CHILD 2 - Then this is where you can choose a parent(Guardian) from the list of existing CPT PEOPLE - select 'Choose As bum Guardian' for POTENTIAL GUARDIAN 3 and follow the forms which should take us to back to the Guardians page and ready for step 2

Talk soon
G

#1266891

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2019-06-12 at 10.00.25 AM.png
Screenshot 2019-06-12 at 9.49.18 AM.png

Hi Geoff,

I think i'm following now. So after i clicked on a child i'm taking to this page. See Screenshot.

This is displayed by view 2599

So after clicking Choose as Bum Guardian i'm taking to the next page with the form with the child selected to Add as Guardian.

From here should I click Add as Guardian ?

Please let me know.
Thanks,
Shane

#1266937

Hi Shane

Yes you have followed this correctly and now if you click 'Add Guardian' this will add them as the selected Childs parent and return you to the Guardians page...

This step I can repeat over and over again, choosing different existing potential guardians...The only difference from the first time is that now the child has a parent, instead of going to the url legacyangel.com/person/child-1 it goes to legacyangel.com/person/parent-1/child-1 (obviously the parent-1 and child-1 are replaced by their auto generated names).

So perhaps you could just go through the same process a couple of times to confirm that you can infinitely change the parent of the child...Then we can move on to the next step which is where the crux of the problem lies..

I shall wait to hear back that you have successfully achieved this...

Best wishes

Geoff

#1267227

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

I'm able to successfully change the guardian indefinitely and each time the new guardian shows up here
hidden link

What is the next step.

Thanks,
Shane

#1267257

Ok great Shane...so obviously the adoption process work fine when the potential guardian already exists...so now we're going to create a new guardian..

Select a child from the guardians page as before but this time on the person template instead of selecting a potential guardian from the list in view ID:2599, select 'Create New Guardian' this takes you to layout ID:2612 which using form ID1787 and the hook we created, creates the New CPT Person, makes them parent of the selected child and then redirects to the guardians page... This part works ok and assigns the newly create PERSON as parent...

THE PROBLEM
When I'm back on the guardians page and now try to select a child from the list in view ID:2548 it takes me to their parents layout page (i.e. the new Person we created in step 3) rather than the child in the list..

Let me know how you get on

Best regards as always

Geoff

#1268309

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

THE PROBLEM
When I'm back on the guardians page and now try to select a child from the list in view ID:2548 it takes me to their parents layout page (i.e. the new Person we created in step 3) rather than the child in the list..

I tried this but it didn't go like this for me. I'm not taken to any parent page layout.

Could you do a short video of this issue for me. I think that can help with my understanding as well. However I do think the issue is something simple as a value not being correct.

Thanks,
Shane

#1268503

Hi Shane

If you try to create a new parent for either of he children now following the same procedure as before it doesn't work...whereas if you choose existing CPT PEOPLE you can do this over and over again...

Can you try with one of the children to keep creating new parents and you will get to the problem..

best regards

Geoff

#1268549

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Geoff,

The only issue I noticed is that when you create a new parent, the child isn't attached to the parent.

So essentially the new Guardian is created but the child is still not adopted.

The procedure is that it should be similar to when you add a pre-existing guardian, where the child is attached correct?

Thanks,
Shane

#1268569

Hi Shane

Apologies Shane...I had the wrong theme activated and the hooks we created to do this are in the functions.php file to a different child theme...I have corrected this now....could you please try the last steps again..

Many thanks

Geoff