Hook

Automatically delete child posts when parent is deleted

The following is intended to work with relationships created with Types 3+. Edit the code to include the slug of the parent post type, and the slug of the relationship. When a parent post is deleted, its children will be deleted, too.

add_action( 'delete_post', 'ts_delete_children', 1, 20 );
function ts_delete_children( $post_id, $post ){

    $parent = 'project'; // Edit parent post type slug

    $relationship = 'project-task'; // Edit relationship slug

    if ( $post->post_type == $parent )
    {
        //get child tasks
        $children = toolset_get_related_posts( $post_id, $relationship, array('query_by_role' => 'parent','role_to_return' => 'child') );

        if ( is_array( $children ) )
        {
            foreach ($children as  $child) 
            {
                wp_delete_post( $child );
            }
        }
    }
}

Consider using the before_delete_post hook if trashing parent posts rather than directly or force deleting them.