Skip Navigation

[Gelöst] I want help for duplicate post with repeatable fieldgroup

This support ticket is created vor 2 Jahren, 7 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 3 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von marcB-6 vor 2 Jahren, 7 Monaten.

Assistiert von: Minesh.

Author
Artikel
#2351793

Hi Minesh,

I see your reply here

https://toolset.com/forums/topic/im-unable-to-duplicate-post-with-its-repeating-field-content-2/

And it's working fine for me but i need some more help from you when i duplicate page it duplicate repeatable field group but i have another repeatable field group inside repeatable field group so how can i copy that 2nd level repeatable field group can you please help me.

Thanks

#2352273

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As this will require custom code, could you please share more details about your structure and share problem URL and admin access details.

Please tell me what is working and where you will require help. Please tell me where you added the custom code hook.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2352379

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

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.

#2352389

Thank you very much minesh my issue is solved.