Could you please try to use the following code and replace it with the existing code (keep backup of your existing code):
function func_add_rfg_entries( $post_id, $post,$update ){
//$allowed_post_types = array("galeria-digital");
//if ( in_array($post->post_type,$allowed_post_types)) {
remove_action( 'save_post', 'func_add_rfg_entries',999,3 );
if($post->post_status != "auto-draft" and $_GET['post_status']!='all') {
$rfg_ids = toolset_get_related_posts($_GET['post'],'section-flex','parent',999,0,array(),'post_id','child');
if(count($rfg_ids) > 0 ) {
foreach($rfg_ids as $k=>$v):
// Copy post metadata
$data = get_post_custom($v);
$my_post = array(
'post_title' => "rfg-entry-".$post_id,
'post_content' => '',
'post_status' => 'publish',
'post_author' => $post->post_author,
'post_type' => 'section-flex');
// Insert the post into the database
$insert_post_id = wp_insert_post( $my_post );
// connecting RFG item to newly cloned $post_id
toolset_connect_posts('section-flex', $post_id, $insert_post_id );
foreach ( $data as $key => $values) {
foreach ($values as $value) {
add_post_meta( $insert_post_id, $key, $value );
}
}
/// you can add remove the nested RFG slugs from the following
$nested_rfgs = array('submenu-item','image-slide','step-section-img-m','specification-multi','3d-image-section-img', 'image-grid-image','quote-slide-f','fact','usp-f','image-grid-tab','contact-person','horizontal-slider','service','logo-bar-logo');
foreach($nested_rfgs as $index=>$rel_slug):
$found_nested_rfg = toolset_get_related_posts($v,$rel_slug,'parent',999,0,array(),'post_id','child');
if(count($found_nested_rfg) > 0 ) {
foreach($found_nested_rfg as $p=>$nested_id):
copy_nested_rfg_items($nested_id,$insert_post_id,$rel_slug);
endforeach;
}
endforeach;
endforeach;
}
}
add_action( 'save_post', 'func_add_rfg_entries',999,3 );
//}
}
add_action( 'save_post', 'func_add_rfg_entries', 999, 3 );
function copy_nested_rfg_items($current_rfg_id,$parent_id,$relationship_slug){
$data = get_post_custom($current_rfg_id);
$title = get_the_title($current_rfg_id);
$my_post = array(
'post_title' => $title,
'post_content' => '',
'post_status' => 'publish',
'post_author' => $post->post_author,
'post_type' => $relationship_slug);
// Insert the post into the database
$insert_post_id = wp_insert_post( $my_post );
// connecting RFG item to newly cloned $post_id
toolset_connect_posts($relationship_slug, $parent_id, $insert_post_id );
foreach ( $data as $key => $values) {
foreach ($values as $value) {
add_post_meta( $insert_post_id, $key, $value );
}
}
}
As you can see with the above code I've added the following code to add the nested RFG entries:
/// you can add remove the nested RFG slugs from the following
$nested_rfgs = array('submenu-item','image-slide','step-section-img-m','specification-multi','3d-image-section-img', 'image-grid-image','quote-slide-f','fact','usp-f','image-grid-tab','contact-person','horizontal-slider','service','logo-bar-logo');
foreach($nested_rfgs as $index=>$rel_slug):
$found_nested_rfg = toolset_get_related_posts($v,$rel_slug,'parent',999,0,array(),'post_id','child');
if(count($found_nested_rfg) > 0 ) {
foreach($found_nested_rfg as $p=>$nested_id):
copy_nested_rfg_items($nested_id,$insert_post_id,$rel_slug);
endforeach;
}
endforeach;
And it calls the function copy_nested_rfg_items() to copy values and connect the nested posts.
Currently I've added all the nested RFG groups:
$nested_rfgs = array('submenu-item','image-slide','step-section-img-m','specification-multi','3d-image-section-img', 'image-grid-image','quote-slide-f','fact','usp-f','image-grid-tab','contact-person','horizontal-slider','service','logo-bar-logo');
You should try to add/remove your desired RFG groups with the above line. I hope it should work or you are welcome to modify the above code as required as its custom code.