[Escalated to 2nd Tier] Delete child posts when parent is deleted
This support ticket is created 4 years, 8 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Tell us what you are trying to do?
When a user deletes a main 'event' entry on the frontend, I'd like all child posts to also be deleted automatically.
Is there any documentation that you are following?
When I click the 'Delete' link, it starts but hangs on 'Deleting..'.
If I refresh the page, the event is no longer shown on that single event frontend. It's also not showing in the list view. However, in this list view, the child post still shows.
In the backend, the parent event still exists, as do any children.
I did identify a typo in the code sample above, on line 13 it should be $relationship not $relationship_slug.
But I'm still having problems getting this to work.
The toolset_get_related_posts function doesn't work when triggered by the delete_post hook (or the slightly earlier before_delete_post hook). There is a basic problem using it in the backend where you need to trash the parent posts before deleting them, and when they are trashed, toolset_get_related_posts no longer gets the connections.
It is possible—in the backend—to get around this by using the wp_trash_post hook instead, to delete the child posts when the parent is trashed.
But that doesn't help in the front-end. When using the cred_delete_post_link shortcode to delete posts and relying on the delete_post hooks the toolset_get_related_posts function doesn't work, it returns an empty array.
I need to consult with the developers about this to find a way past this impasse, and I'll get back to you.
The feedback is that the toolset_get_related_posts API function should be updated to make the status of the origin post more flexible so that it can include trashed posts.
It's a small change which they should be able to provide pretty quickly, and once they have I can update the code to get this working.