Hook in when a post is deleted, check for the post type, then manipulate post_parent
of potential child posts (or delete the posts):
function wp_dev_174635_update_posts( $parent_id ) {
$parent = get_post( $parent_id );
if ( $parent->post_type !== 'type2' ) {
return;
}
$posts = get_posts( array(
'post_type' => 'type1',
'post_parent' => $parent_id,
) );
foreach ( $posts as $post ) {
// EITHER: Reset post parent entry
wp_update_post( array(
'ID' => $post->ID,
'post_parent' => 0,
) );
// OR: Delete post
// wp_delete_post( $post->ID );
}
}
add_action( 'delete_post', 'wp_dev_174635_update_posts' );