i have done this coding, but is not disconnecting it. It's work the delete part, but not the disconnction of relationships.
/**
* Automatically delete child posts when deleting a parent
*/
add_action( 'before_delete_post', 'ts_delete_children', 9, 2 );
function ts_delete_children( $post_id, $post ){
$parent_type = 'intervento'; // Edit parent post type slug
$relationship_slug = 'intervento-piazza-di-lavoro'; // Edit relationship slug
if ( $post->post_type === $parent_type ){
$children = toolset_get_related_posts( $post_id, $relationship_slug, ['query_by_role' => 'parent','role_to_return' => 'child','args' => ['post_status' => [ 'publish', 'trash' ] ] ] );
if ( is_array( $children ) )
{
foreach ($children as $child)
{
$relationship_slug_militi= 'piazza-di-lavoro-milite';
$militi= toolset_get_related_posts( $child, $relationship_slug_militi, ['query_by_role' => 'parent','role_to_return' => 'child','args' => ['post_status' => [ 'publish', 'trash' ] ] ] );
foreach ($militi as $milite)
{
$relationship_slug_radio= 'radio-milite';
$radios= toolset_get_related_posts( $milite, $relationship_slug_radio, ['query_by_role' => 'child','role_to_return' => 'parent','args' => ['post_status' => [ 'publish', 'trash' ] ] ] );
foreach ($radios as $radio){
toolset_disconnect_posts('radio-milite', $radio, $milite );
}
}
wp_delete_post( $child );
}
}
}
}