Skip Navigation

[Resolved] WordPress hierarchy in custom posts

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

Assisted by: Shane.

Author
Posts
#1268571

Here is the hook we created:

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');

}
}

#1271075

Shane
Supporter

Languages: English (English )

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

Hi Geoff,

Can we confirm the exact issue is that when you create a new guardian the child doesn't get assigned to the guardian correct?

#1271621

Hi Shane

The child does seem to get attached the first time but I can't repeat the process in the same way as the existing guardians..so I want to be able to keep cresting new guardians through the same process..

So here's what happens when I try it in your login:
Guardians Page - I select CHILD 2 - choose/change Parent
Takes me to website.com/PERSON/CHILD-PARENT/CHILD 2 (the actual url is:hidden link)
I select 'Create New Guardian' which takes me to hidden link
Here I create a new CPT PERSON to become the guardian of the child post that is passed in the url (child_post_id=5116) - The hook we created sets up the parent/child relationship - Then I select submit which takes me back to the 'Guardians' Page...however CHILD 2 now says that CHILD 2 is the parent and not the newly created Parent....

Hope this makes sense...speak soon

Best regards

Geoff

#1271999

Shane
Supporter

Languages: English (English )

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

Hi Geoff,

The hooks are firing but the wordpress default function isn't working.

As i previously advised it seems that something is causing the default wordpress functions not to work.

Could you remove again all your hooks and test just this one by itself as I see no reason why it shouldn't work since the Forms hook is working.

Thanks,
Shane

#1274423

Hi Shane

I am working through this and will get back to you shortly

Best wishes
Geoff

#1274651

Shane
Supporter

Languages: English (English )

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

Hi Geoff,

No problem, just update me when you can.

Thanks,
Shane

#1274935

Hi Shane

Ok I've moved forward slightly...

I've isolated the hook and the problem still exists..so there is nothing conflicting...

What is happening is that I create a child here: (e.g. CHILD 1)

hidden link

then go to the guardians page here:
hidden link
Then choose the child I've created (choose/Change Parent) - Then create a new Guardian ...

But instead of the Guardian becoming the parent ..the opposite happens i.e. The CHILD 1 becomes the parent of the new guardian....and any subsequent guardians that are created all become children of CHILD 1..

I have set up CHILD 1 for you already ..so if you login and navigate to
hidden link
then try to loop through the process of creating a new guardian each time you'll discover the problem...

I'll look forward to hearing back from you

Best regards
Geoff

#1275857

Shane
Supporter

Languages: English (English )

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

Hi Geoff,

So I found the issue why it is always saying Child 1, It's because you are trying to pull the Parent Data.
hidden link

But what seems to be happening is that your code is setting the guardian as a child of the post.

Perhaps we can look at it from here.

Thanks,
Shane

#1275887

Hi Shane

Ok great....seems like we're moving forward a bit... so what I need in this list is to show the parents name as it does but I need to click on choose/change parent to take you to the selected child's page where you can 'create new guardian' and it will add the new CPT Person an the parent then redirect to the guardians page..

Let me know what you think
Regards
Geoff

#1276155

Shane
Supporter

Languages: English (English )

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

Hi Geoff,

I think we are close on this one.

Will post when I'm able to resolve this.

Where do I go to create a new child on the frontend, because I see this child doesn't have the parent attribute option.

Thanks,
Shane

#1276187

Hi Shane

I will look forward to hearing back from you...

To create a new child.. go to url
hidden link

Best of luck!
Geoff

#1276707

Shane
Supporter

Languages: English (English )

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

Hi Geoff,

So you form is generating your new parents, with the same slugs.

This is what I believe is causing the issue. So instead of storing the person's name in a custom field, why not just let their name be the post title and add back the post title field to the form that is being used. This will allow the posts to not be created with an autodraft title but rather with an actual title.

Please let me know what you think of this as there is quite a few issues i'm having.

Thanks,
Shane

#1276715

Hi Shane

Ok great..that sounds like you're getting somewhere...Can you implement this please... also would this be an issue if by chance there were 2 people with the same name?

But sounds great...thanks for your continued support

Best regards

Geoff

#1276743

Shane
Supporter

Languages: English (English )

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

Hi Geoff,

Should now be resolved.

I found that the main issue was that on the form the parent information was being set for the guardians as well. I went ahead and deleted that field from the form and made some adjustments so the persons name is stored as the title.

Let me know what you think of this.

Thanks,
Shane

#1276939

That's fantastic Shane...looks like its working fine..I'm going to do some testing and will get back to you..

Thank you !

Speak soon

Geoff