Skip Navigation

[Resolved] Copy duplicate values from RFGs

This support ticket is created 3 years, 9 months 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Author
Posts
#1966509

Tell us what you are trying to do?

I've been following Minesh's thread at: https://toolset.com/forums/topic/im-unable-to-duplicate-post-with-its-repeating-field-content-2/

And am trying to understand - is there a way (aside from the above) to duplicate a page, and still retain ALL of the value, including those are inside a repeater?

I'm using Duplicate Page Pro, but would prefer the other duplicate page plugin (in case there is any incompatibility.)

Also, I'm not sure which was the repeater field group in question: galeria-digital or grilla-galeria?

#1967723

Hi,

Thank you for contacting us and I'd be happy to assist.

I'm afraid, there is no built-in feature available for this, so you'll need some code customization, as Minesh suggested in the other thread.

That code snippet is designed to work when a post is duplicated through the "Yoast Duplicate Post" plugin ( ref: https://wordpress.org/plugins/duplicate-post/ ), but, you can adjust it to work with any post duplicate plugin that offers some customization hook or filter.

And in that thread, "galeria-digital" is the parent post type, and the "grilla-galeria" is the repeating field group in it.

regards,
Waqar

#1969749

Hi Waqar,

Thank you, that is too bad to hear. Could you please forward to the team as a feature request? It is widely used and very helpful from a workflow UX perspective.

#1970301

Thanks for the update and I can understand that this can be useful in a number of cases.

I'll be happy to pass this on internally.

#1972993

Hi Waqar,

Thank you for your reply. I have aimed to replicate Minesh's solution and have been able to partially get it working.

hidden link

The main issue seem to be:

1.) The values of the RFG fields are there, but seem like "ghost values", where you can't seem to see or edit them on the backend in the CPT entry

2.) When I hit "publish" and it goes from draft to "published" and from "published" to "draft", there is a critical PHP error that flashes, and when you refresh it, it goes away. Which seems to suggest there is some type of an issue in the status change workflow?

Much appreciate your help!

Kind regards,

#1973139

I'll need to perform some tests on my website, to see if I can reproduce this.

As soon as this testing completes, I'll share my findings with you.

Thank you for your patience.

#1974535

Thank you for waiting.

On my test website, I was able to make this work, using updated code that uses the "dp_duplicate_post" hook from the "Yoast Duplicate Post" plugin:
hidden link

Example:


function my_custom_dp_duplicate_post( $new_post_id, $post ) {
	$parent_post = 'book';
	$rfg_post = 'book-rfg';
	if ( get_post_type( $new_post_id ) == $parent_post ) {
		$rfg_ids = toolset_get_related_posts($post->ID, $rfg_post,'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'	=> get_the_title($v),
						'post_content'	=> '',
						'post_status'	=> 'publish',
						'post_author'	=> $post->post_author,
						'post_type'		=> $rfg_post
					);
					// 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($rfg_post, $new_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( 'dp_duplicate_post', 'my_custom_dp_duplicate_post', 50, 2 );

Please change "book" and "book-rfg" with your parent and child/repeating field group post type slugs, respectively.

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/