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);
}
}
}
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'
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?