Skip Navigation

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

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 6 años, 1 mes. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 8 respuestas, tiene 2 mensajes.

Última actualización por geoffD hace 6 años, 1 mes.

Asistido por: Minesh.

Autor
Mensajes
#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

enlace oculto

...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:
enlace oculto

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

Idiomas: Inglés (English )

Zona horaria: 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: enlace oculto
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:
enlace oculto

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

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

So to check if I understand you correctly.

I'm on this page: enlace oculto

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

Idiomas: Inglés (English )

Zona horaria: 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.
=> enlace oculto

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