Skip Navigation

[Resuelto] Delete all child posts when delete parent

This support ticket is created hace 6 años, 8 meses. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Luo Yang hace 6 años, 8 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#629408

Hi!
I'm trying to delete all child posts when delete a parent post.

I tried the following threads, but it does not work.
https://toolset.com/forums/topic/delete-child-posts-cascade-deletes/
https://toolset.com/forums/topic/delete-all-children-cpt-when-delete-parent-cpt/
Has the way of doing it changed?

I have a view where I show a CPT "client" in a loop and for each element I have a link to delete it (cred_delete_post_link).
I need help with this.

Thanks.

#629453

Hello,

It does not change, please check these:
1) Check the CRED delete link shortcode, make sure it is using attribute: action="delete", for example:
[cred_delete_post_link action="delete" text="Delete %TITLE%" message="Are you sure you want to delete this post?" message_show="1"]

It will be able to trigger the wordpress action hook "delete_post" when user click the delete link
https://developer.wordpress.org/reference/hooks/delete_post/

2) In your custom PHP codes, this line:

$ids = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_wpcf_belongs_company_id' AND meta_value = '".$pid."'" );

You will need to replace "company" with the parent post type slug