Hi,
Thank you for contacting us and I'd be happy to assist.
Your observation is correct and when a parent post of a repeatable field group is deleted, its relationship connections with child repeatable field group items are deleted, but those child post items are not deleted.
We have an internal ticket to improve this in future releases, however, I don't have a time estimate to share at the moment.
For now, you can use a custom function attached to the "after_delete_post" hook ( ref: https://developer.wordpress.org/reference/hooks/after_delete_post/ ) which is executed every time a "story" post type is deleted. The function will cycle through all the available "bill-services" repeatable post items and delete the ones for which a parent "story" post doesn't exist:
add_action( 'after_delete_post', 'custom_services_cleanup_func', 1, 2 );
function custom_services_cleanup_func( $postid, $post ) {
// exit if post that is getting deleted is not of type "story"
if ( 'story' !== $post->post_type ) {
return;
}
// get all repeating field post types 'bill-services'
$args = array(
'post_type' => 'bill-services',
'posts_per_page' => -1,
'post_status' => 'publish',
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
// get the parent 'story' post
$get_parent = toolset_get_related_posts( $post->ID, 'bill-services', 'child', 1, 0, array(), 'post_id', 'parent' );
// if no parent exists, delete the current 'bill-services' post
if(empty($get_parent)) {
wp_delete_post( $post->ID, true);
}
}
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar