Title: [Plugin: Duplicate Post] Magic-fields
Last modified: August 20, 2016

---

# [Plugin: Duplicate Post] Magic-fields

 *  [BBLYTH](https://wordpress.org/support/users/bblyth/)
 * (@bblyth)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-duplicate-post-magic-fields/)
 * Hi Lopo,
 * Thanks for your fantastic plugin, which works really well.
 * Unfortunately, I have 3 fields for my posts (using the plugin Magic-fields) and
   your plugin duplicates the first field perfectly but only snippets of the other
   two.
 * Any chance you might be able to improve it to accommodate all the fields? Please!!!
 * With warm wishes
 * Bryony
 * [http://wordpress.org/extend/plugins/duplicate-post/](http://wordpress.org/extend/plugins/duplicate-post/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Enrico Battocchi](https://wordpress.org/support/users/lopo/)
 * (@lopo)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-duplicate-post-magic-fields/#post-2566699)
 * What kind of fields are they?
 * I had the chance to use Magic Fields once, I seem to remember that it uses non-
   standard tables: if so, you would have to ask Magic Fields’ developers if the
   can write a function to clone these fields as specified in my plugin’s FAQ…
 *  [Mladen](https://wordpress.org/support/users/mlajo/)
 * (@mlajo)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-duplicate-post-magic-fields/#post-2566850)
 * hi, I’m not experienced programmer but I manage to do some kind of function to
   copy Magic fields so here it is if somebody need..
    just put it in functions.
   php
 *     ```
       function mf_copy_post($new_post_id, $old_post_object){
       	global $wpdb;
       	$i=0;
       	$repeated_filde_name = NULL;
   
           $query = $wpdb->prepare( "SELECT * FROM ".MF_TABLE_POST_META." WHERE post_id = %d", array( $old_post_object->ID) );
           $fields = $wpdb->get_results( $query, ARRAY_A);
   
       	foreach ($fields as $key => $field) {
       		if ($repeated_filde_name == $field['field_name']){
       			$i++;
       		} else {
       			$i=0;
       		}
   
       		$repeated_filde_name = $field['field_name'];
       		$query = $wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."postmeta WHERE post_id = $new_post_id AND meta_key='{$field['field_name']}' LIMIT 1 OFFSET $i " );
       		$new_fields = $wpdb->get_row( $query, ARRAY_A);
       		$field['meta_id'] = $new_fields['meta_id'];
       		$field['post_id'] = $new_post_id;
   
       		$res = $wpdb->insert(
       				MF_TABLE_POST_META,
       				$field
       			);
   
       		$repeated_filde_name = $field['field_name'];
   
       	}
   
       }
       add_action( "dp_duplicate_post", "mf_copy_post",  10, 2);
       ```
   
 *  [relish1227](https://wordpress.org/support/users/relish1227/)
 * (@relish1227)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-duplicate-post-magic-fields/#post-2566880)
 * Hi, I’m having the same issue.
 * My Magic Fields write panel has two groups — one containing regular fields and
   the other being a group of fields that can be duplicated (so you can “Add another”
   and a whole new set of the same fields is available).
 * When I use the Duplicate Post plugin, it duplicates the regular MF fields just
   fine. But it doesn’t duplicate the multiple sets of fields from that second group.
   For instance, I have 7 instances of that second group of fields and I don’t get
   any instances duplicated.
 * When I use mlajo’s function, it copies on instance of that group — but not all
   7. So one step forward… but not quite enough!
 * Would love to know if anyone has managed to resolve this issue…
 * Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘[Plugin: Duplicate Post] Magic-fields’ is closed to new replies.

 * ![](https://ps.w.org/duplicate-post/assets/icon-256x256.png?rev=2336666)
 * [Yoast Duplicate Post](https://wordpress.org/plugins/duplicate-post/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/duplicate-post/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/duplicate-post/)
 * [Active Topics](https://wordpress.org/support/plugin/duplicate-post/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/duplicate-post/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/duplicate-post/reviews/)

 * 3 replies
 * 4 participants
 * Last reply from: [relish1227](https://wordpress.org/support/users/relish1227/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-duplicate-post-magic-fields/#post-2566880)
 * Status: not resolved