Skip Navigation

[Resolved] I'm unable to duplicate post with its repeating field content.

This support ticket is created 4 years, 1 month ago. 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.

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)

This topic contains 5 replies, has 2 voices.

Last updated by leonardoL 4 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1815659

Hi:
Minesh was helping me but I took to long to respond and now the ticket is closed.
https://toolset.com/forums/topic/im-unable-to-duplicate-post-with-its-repeating-field-content/

Could you help me with the code like Minesh was doing, please (I have the backup now):

"However - we can workaround this by adding some custom code using the action "dp_duplicate_post" when you installed and activated the plugin: hidden link
=> hidden link

If you are not sure how to do that, Can you please share the post that you want to duplicate it and send me access details so I will try to help you out by adding the required code to the hook: dp_duplicate_post"

Tell us what you are trying to do?
Duplicating a post (using plugins) which it have a repetible group, with all its contents . The plugin clones the post but not the content in the repetible group.
There is a way to do it?

Is there any documentation that you are following?
No

Is there a similar example that we can see?
I don't know.

What is the link to your site?
I tried in more than one site.

#1816617

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share what post you want to duplicate with what repeating field group?

*** 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.

#1817785

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've added the following code to your current theme's functions.php file:


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'],'grilla-galeria','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' => 'grilla-galeria');
 
      
	  // 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('grilla-galeria', $post_id, $insert_post_id );
	  
	  foreach ( $data as $key => $values) {
				foreach ($values as $value) {
					add_post_meta( $insert_post_id, $key, $value );
				}
    	  }			 
      
		endforeach;
          
           
         
        }
      }
             
             
   add_action( 'save_post', 'func_add_rfg_entries',999,3 );
    }
}
add_action( 'save_post', 'func_add_rfg_entries', 999, 3 );

Your post have 28-29 repeating field group items and each repeating field group having more than 10 custom fields.

When I try to duplicate post, I gest "Request Timeout" error, that you will require to manage with your server/hosting support otherwise, if you refresh the page, you will see the post is duplicated and when you edit it I can see the repeating field group entries are also get copied successfully.

Here is the example of post that is duplicated with "Request Timeout" error.
=> hidden link

#1818131
Captura de pantalla 2020-10-20 131438.png

Hi:

It clones the post but I can not edit it in any way, it always return an error, even with the original posts.

Regards

#1818143

Minesh
Supporter

Languages: English (English )

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

I've changed the following line of the code from:

if($post->post_status != "auto-draft" and $_GET['post_status']!='all') {

To:

if(isset($_GET['action']) and $_GET['action']=='duplicate_post_save_as_new_post') {

It should be OK now and you should be able to edit the post.

#1818181

My issue is resolved now. Thank you!