Skip Navigation

[Resolved] Front end duplication of post not saving title change

This support ticket is created 6 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
- 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 3 replies, has 2 voices.

Last updated by grahamA 6 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#617941

I am trying to: duplicate a post on the front end and allow the user to change the title and content - a sort of 'Save as' function

Link to a page where the issue can be seen: hidden link

I expected to see:

Instead, I got: an exact duplicate without any changes saved

I am happy to give you access to the site as it is experimentation only.

Thanks Gaham

functions.php

 // Add Shortcode [duplicate_post]
function duplicate_posts() {
 
    // Code
duplicate_post_clone_post_link( __('Clone this Post','duplicate-post'), $before, $after, $id );
}
add_shortcode( 'duplicate_post', 'duplicate_posts' );



add_action('cred_save_data_264', 'duplicate_post', 10, 2);
function duplicate_post($post_id, $form_data) {
    // get data of original post
    $post = get_post( $form_data['container_id'], ARRAY_A );
    // update the new post with this data
    $post['ID'] = $post_id;
    $post['post_title'] = 'Copy of ' . $post['post_title'];
    wp_update_post( $post );
    // get fields of original post
    $fields = get_post_custom( $form_data['container_id'] );
    // update the new post with these fields
    foreach ($fields as $key => $values) {
        foreach ($values as $value) {
            add_post_meta($post_id, $key, $value, false);
        }
    }
}
#618118

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Could you please share exact steps information I need to follow to duplicate the post and what is your expected output?

#618365

Hi Minesh

step 1. go to hidden link
step 2. Login as user 'tom' pw 'toolset'
step 3. Go to frontend of site
step 4. Click 'Button 1'

The current behaviour after clicking button 1 in my site is not desired.

Desired result = Click button 1 then present user with request to rename the duplicated post title. Then display a duplicate of post #287 where user has changed the post title in the list of posts in the front end where I currently see #287 with a new name.

Adding ' Copy of' multiple times to an unchanged post name is not desirable.

You have full admin access to back end - user 'toolset' pw 'toolset'

Thanks

#618943

Minesh
Supporter

Languages: English (English )

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

Desired result = Click button 1 then present user with request to rename the duplicated post title.
==> I see the edit form is available when I click on the button.

Then display a duplicate of post #287 where user has changed the post title in the list of posts in the front end where I currently see #287 with a new name.
==> Sorry - I do not understand this, what you want to do here - is the post title displayed with edit form is not correct one? You want to display another post title?

Adding ' Copy of' multiple times to an unchanged post name is not desirable.
==> Do you mean that if post title is changed then and then "copy of" should be added?

#618956