Skip Navigation

[Resolved] I neeed to set a Duplicate Post link on front end (no user access admin pages)

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 7 replies, has 2 voices.

Last updated by Minesh 1 year, 1 month ago.

Assisted by: Minesh.

Author
Posts
#2659185
Toolset_Object Single Template_2.JPG
Toolset_Object Single Template_1.JPG
Toolset_Object Single Template_1.JPG

This Duplicate post link has to be set in 2 places:
- on the custom type Objet single template
- in the View loop displaying all Objets of a given Collection or Institution

Is there any documentation that you are following?
I have found a php function in :
- Tooset forum : https://toolset.com/forums/topic/duplicate-custom-posts-at-front-end/
--- 8 years old : so probably not not up-to-date
- Yoast plugin Duplicate Post : hidden link
I tried both as I am able to : I put the function into the Code Snippets plugin and activated it.
But it does not work :
- on the Single Objet Editing Template, when updating, I get the message :
"La mise à jour a échoué. La réponse n’est pas une réponse JSON valide."
in English : "The update failed. The response is not a valid JSON response."

Is there a similar example that we can see?
- see the 2 screen captures below

What is the link to your site?
hidden link
The admin temporary access for Toolset is :
- user name : toolset
- passsword : passwordremoved

Thank you for helping resolve this issue : it would be so useful to my client to be able to duplicate an existing Objet, without having to enter all similar fields contents...
Best regards,
Francesco De Grandi

#2659441

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As per the support request - the duplicate post only applies on the backend.
- https://wordpress.org/support/topic/enable-duplicate-post-from-the-front-end/

I've disabled the shortcode "duplicate_post" you added to the code snippet:

Here is how I've adjusted the code added to the code snippet:
=> hidden link

function func_show_duplicate_post_link_on_frontend($atts) {
    $atts = shortcode_atts(array(
        'text' => __('Dupliquer', 'duplicate-post')
    ), $atts);

    ob_start();
    if (function_exists('duplicate_post_clone_post_link')) {
        echo duplicate_post_clone_post_link($atts['text']);
    }
    return ob_get_clean();
}
add_shortcode('duplicate_post_link', 'func_show_duplicate_post_link_on_frontend');

function func_duplicate_post_from_frontend($new_post_id) {
$status = "publish"; // Update event based on status 
	
$post = array(
'ID' => $new_post_id,
'post_status' => $status,
); wp_update_post($post); // Perform some actions after copying the post.
wp_safe_redirect(get_permalink($new_post_id), 301);
exit();
}

add_action('duplicate_post_post_copy', 'func_duplicate_post_from_frontend');

I've added the following shortcode to your content template:
=> hidden link

[duplicate_post_link]

Can you please confirm it works as expected:
- hidden link

#2659565

Hi Minesh,
Thank you for your rapid and very substantial response !

The shortcode you added with the seriously updated function in Snippets work fine.
And it is published immediately, which is the prefered status in this case.

There is nevertheless a detail that would improve the solution even more :
- while cloning it, would it be possible to append the title of the custom post with the string : "copie"
- this would immediately signal the user that it is not the original post, but it's copy.

Thank you for letting me know if it is possible to update the function in that way. I do not have the wordpress/php profitiency to do it myself.

Best regards,
Francesco De Grandi

#2659575

Minesh
Supporter

Languages: English (English )

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

I've adjusted the code as given under added to your code snippet:

function func_duplicate_post_from_frontend($new_post_id) {
$status = "publish"; // Update event based on status 
	
$post = array(
'ID' => $new_post_id,
'post_status' => $status,
'post_title' => "Copy : ".get_the_title($new_post_id)
); wp_update_post($post); // Perform some actions after copying the post.
wp_safe_redirect(get_permalink($new_post_id), 301);
exit();
}

add_action('duplicate_post_post_copy', 'func_duplicate_post_from_frontend');

Where - I've added the following line of code:

'post_title' => "Copy : ".get_the_title($new_post_id)

Can you please confirm it works as expected.

#2659595

Hi Minesh,
Thank you very much : it works very well.
I decided not to put the shortcode on the single Objet template any more, in order to streamline the workflow of the duplication process.

I have to say that I am amazed at what can be achieved with Toolset : this site muselink.ch is destined to be a mulri-museum platform, allowing collaboration between the museums, therefore requirering tight access control and a great diversity of options for custom types templates and forms.

I have to thank the whole Toolset team for it : BRAVO ! Keep up your excellent work...

This issue is therefore resolved.
Thanks again,
Francesco De Grandi

#2660087

Hi Manesh,
There is another element to fix, in order to complete this functionality :
- when duplicating, the permalink/slug of the duplicated Objet is set to : copie-source-objet-name
- then, when updating the Object Title, thre permalink stays the same, and is not updated to the new objet name

Is there a way to update the parmalink/slug of the new Objet on the publication form (without access to the admin dashboard) ?

This is a necessary, indispensable functionality. Thank you for helping me achiev it.
Best regards,

Francesco De Grandi

#2660089
Toolset_Object Edit Template_Permalink.JPG

Hi Manesh,
There is another element to fix, in order to complete this functionality :
- when duplicating, the permalink/slug of the duplicated Objet is set to : copie-source-objet-name
- then, when updating the Object Title, thre permalink stays the same, and is not updated to the new objet name,
as you can see in the attached screen shot.

Is there a way to update the parmalink/slug of the new Objet on the publication form (without access to the admin dashboard) ?

This is a necessary, indispensable functionality. Thank you for helping me achiev it.
Best regards,

Francesco De Grandi

#2660127

Minesh
Supporter

Languages: English (English )

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

As per our support policy - we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery. May I kindly ask you to close this ticket and we will continue with the following split ticket:
- https://toolset.com/forums/topic/split-i-neeed-to-set-a-duplicate-post-link-on-front-end-no-user-access-admin-pages-update-post-slug-for-duplicated-post/

You can mark resolve this ticket with different message something like "this issue is now resolved".

Thank you for understanding.