Skip Navigation

[Resolved] Split: Hierarchy of same post type – create new parent

This thread is resolved. Here is a description of the problem and solution.

Problem:
Split: Hierarchy of same post type - create new parent

Solution:
You can use Toolset Forms (CRED) hook "cred_save_data" to set parent for your Hierarchical post type using "post_parent" column.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/split-hierarchy-of-same-post-type-create-new-parent/#post-1120832

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 6 years, 1 month 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.

Our next available supporter will start replying to tickets in about 0.35 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by geoffD 6 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1119919

Hi Minesh

That's perfect thank you...just what I need...

The second part of my problem is to create a new PARENT rather than an existing one... so on the page

hidden link

...you would select a CHILD to give a parent to by clicking 'Choose Parent'.. That would then take you to the CHILD page with the list of potential PARENTS but underneath is now a button saying 'Create NEW PARENT' ..this takes you to the page:
hidden link

Where there is a form to create a new PERSON so I need this person to be the CHILD's PARENT..

Thank you for your help

Regards

Geoff

#1119923

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - are you already using any Toolset Forms hook here to connect child to parent?

#1119955

Hi Minesh

Thank you for continuing this ticket

No I'm not using Toolset hooks to connect child/parent as I'm using the WordPress post heirachy as you demonstrated in my last query - connected to this ticket.

Both there PARENT and the CHILD are the same CPT 'PEOPLE'... I need to achieve

1. Select a CHILD from the list on this page: hidden link
That would then take you to the CHILD page with the list of potential PARENTS but underneath is now a button saying 'Create NEW PARENT' ..this takes you to the page:
hidden link

Where there is a form to create a new PERSON so I need this person to be the CHILD's PARENT..

Thank you for your help

Regards

Geoff

#1119957

p.s. I'm happy for you to use the same login credentials as last time

Regards

Geoff

#1120701

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

So to check if I understand you correctly.

I'm on this page: hidden link

So, when I click on 'Create NEW PARENT' so when new person is created using this form "Create NEW PARENT'" you want to set this newly created parent as the parent of child-2 post - correct?

#1120767

His Minesh

Yes that's exactly what I want to happen....Many thanks

Very best regards

Geoff

#1120832

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now.

I've added following code to your current theme's functions.php file:


add_action('cred_save_data','func_update_parent_field',10,2);
function func_update_parent_field($post_id,$form_data) {
    if ($form_data['id']==2613) {
       wp_update_post(array(
        'ID' => $_REQUEST['child_post_id'], 
        'post_parent' => $post_id
    ));
    }
}

When you click on "Create NEW PARENT" I'm passing the child post ID in URL and catching at cred_save_data action.
=> hidden link

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1120920

My issue is resolved now. Thank you Minesh!

#1121711

Hi Minesh

Apologies but there is one last thing I forgot about that I need to do related to this thread.

I need the custom field 'Adopted' of the CHILD whose child post ID you pass in the URL to become 'Yes' when the new PARENT is created.

I'm happy for you to use the same login details as before...

I really appreciate your help...I'm also learning at the same time!

Many thanks

Geoff