The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Duplicate PHP & 2 entries

Labels

This Discussion is public

Notifications

Hey All

I'm trying to set up the php example for duplicating posts on the front end. All is working as expected however I have two duplicates! The form in question has a repeatable section which is why I can't use their regular method of duplication and I think this is causing the issue.

Has anyone else had this problem? Any ideas how I could go about trouble shooting the issue?

Any thoughts would really help!

Regards

Matt

This is what I'm using so far...

The link in the href is:
[siteurl]/voyages/my-passage-plans/duplicate/?duplicate_id=[id]&user_id=[342 show=ID]

The shortcode is:
duplicate_entry_form id=23 entry_id=duplicate_id field_id=1341

The code is:
add_shortcode( 'duplicate_entry_form', 'frm_duplicate_entry_form' );
function frm_duplicate_entry_form( $atts ) {
$old_id = $atts['entry_id'];
if ( ! empty( $old_id ) && ! is_numeric( $old_id ) ) {
$old_id = absint( $_GET[ $old_id ] );
}
$user_id_field = absint( $atts['field_id'] );
$new_entry_id = FrmEntry::duplicate( $old_id );

// set the new entry to the ID of the current user
global $wpdb;
$wpdb->update( $wpdb->prefix .'frm_items', array( 'user_id' => get_current_user_id() ), array( 'id' => $new_entry_id ) );
$wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => get_current_user_id() ), array( 'item_id' => $new_entry_id, 'field_id' => $user_id_field ) );
return FrmFormsController::get_form_shortcode( array('id' => $atts['id'], 'entry_id' => $new_entry_id ) );
}

Discussion closed.