Duplicate Posts, Pages and Custom Post Types Without Plugin
It is very handy to have a possibility to duplicate posts in WordPress when you work with a lot of similar posts. Especially if the posts have the same custom fields values.
It means that you do not have to re-enter custom fields, post tags and categories each time.
If you need the same functionality for WordPress Multisite, check out my plugin.
Below on the screenshot you can see what we are going to create in this tutorial. And one more thing β we are going to duplicate posts programmatically.

This is enough easy to do, so, look at the following code, insert it into your current or child theme functions.php
file or your own custom plugin.
/**
* @snippet Duplicate posts and pages without plugins
* @author Misha Rudrastyh
* @url https://rudrastyh.com/wordpress/duplicate-post.html
*/
// Add the duplicate link to action list for post_row_actions
// for "post" and custom post types
add_filter( 'post_row_actions', 'rd_duplicate_post_link', 10, 2 );
// for "page" post type
add_filter( 'page_row_actions', 'rd_duplicate_post_link', 10, 2 );
function rd_duplicate_post_link( $actions, $post ) {
if( ! current_user_can( 'edit_posts' ) ) {
return $actions;
}
$url = wp_nonce_url(
add_query_arg(
array(
'action' => 'rd_duplicate_post_as_draft',
'post' => $post->ID,
),
'admin.php'
),
basename(__FILE__),
'duplicate_nonce'
);
$actions[ 'duplicate' ] = '<a href="' . $url . '" title="Duplicate this item" rel="permalink">Duplicate</a>';
return $actions;
}
/*
* Function creates post duplicate as a draft and redirects then to the edit post screen
*/
add_action( 'admin_action_rd_duplicate_post_as_draft', 'rd_duplicate_post_as_draft' );
function rd_duplicate_post_as_draft(){
// check if post ID has been provided and action
if ( empty( $_GET[ 'post' ] ) ) {
wp_die( 'No post to duplicate has been provided!' );
}
// Nonce verification
if ( ! isset( $_GET[ 'duplicate_nonce' ] ) || ! wp_verify_nonce( $_GET[ 'duplicate_nonce' ], basename( __FILE__ ) ) ) {
return;
}
// Get the original post id
$post_id = absint( $_GET[ 'post' ] );
// And all the original post data then
$post = get_post( $post_id );
/*
* if you don't want current user to be the new post author,
* then change next couple of lines to this: $new_post_author = $post->post_author;
*/
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;
// if post data exists (I am sure it is, but just in a case), create the post duplicate
if ( $post ) {
// new post data array
$args = array(
'comment_status' => $post->comment_status,
'ping_status' => $post->ping_status,
'post_author' => $new_post_author,
'post_content' => $post->post_content,
'post_excerpt' => $post->post_excerpt,
'post_name' => $post->post_name,
'post_parent' => $post->post_parent,
'post_password' => $post->post_password,
'post_status' => 'draft',
'post_title' => $post->post_title,
'post_type' => $post->post_type,
'to_ping' => $post->to_ping,
'menu_order' => $post->menu_order
);
// insert the post by wp_insert_post() function
$new_post_id = wp_insert_post( $args );
/*
* get all current post terms ad set them to the new post draft
*/
$taxonomies = get_object_taxonomies( get_post_type( $post ) ); // returns array of taxonomy names for post type, ex array("category", "post_tag");
if( $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
$post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
wp_set_object_terms( $new_post_id, $post_terms, $taxonomy, false );
}
}
// duplicate all post meta
$post_meta = get_post_meta( $post_id );
if( $post_meta ) {
foreach ( $post_meta as $meta_key => $meta_values ) {
if( '_wp_old_slug' == $meta_key ) { // do nothing for this meta key
continue;
}
foreach ( $meta_values as $meta_value ) {
add_post_meta( $new_post_id, $meta_key, $meta_value );
}
}
}
// finally, redirect to the edit post screen for the new draft
// wp_safe_redirect(
// add_query_arg(
// array(
// 'action' => 'edit',
// 'post' => $new_post_id
// ),
// admin_url( 'post.php' )
// )
// );
// exit;
// or we can redirect to all posts with a message
wp_safe_redirect(
add_query_arg(
array(
'post_type' => ( 'post' !== get_post_type( $post ) ? get_post_type( $post ) : false ),
'saved' => 'post_duplication_created' // just a custom slug here
),
admin_url( 'edit.php' )
)
);
exit;
} else {
wp_die( 'Post creation failed, could not find original post.' );
}
}
/*
* In case we decided to add admin notices
*/
add_action( 'admin_notices', 'rudr_duplication_admin_notice' );
function rudr_duplication_admin_notice() {
// Get the current screen
$screen = get_current_screen();
if ( 'edit' !== $screen->base ) {
return;
}
//Checks if settings updated
if ( isset( $_GET[ 'saved' ] ) && 'post_duplication_created' == $_GET[ 'saved' ] ) {
echo '<div class="notice notice-success is-dismissible"><p>Post copy created.</p></div>';
}
}
And now some comments about this code:
- If you’re interested only in how to duplicate a page in WordPress without plugin, it is enough for you to use
page_row_actions
filter hook (line 11), if you’re interested in duplicating posts and custom post types,post_row_actions
is for you (line 9). - In the code you can also find some security checks, I am using Nonces and clean
$_GET[ 'post' ]
withabsint()
function. - In line 71-85 you can change post data for you needs. For example we clone posts as drafts, but you can set a
publish
post status. - In line 107-109 we prevent copying meta with key
_wp_old_slug
, it is important to prevent redirects.

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Thanks a lot. So simple to add to functions.php and works great on WP 3.6.1.
You saved me a lot of time. Thanks again.
Christophe
Same here. Thank you!
Hi,
thanks for this great plugin.
Just what I was lookin’ for. Works like a charm :-)
Ralf.
Hi,
glad you like it :)
Ready to add the function to my Event plugin. Going to use it for setting up repeating events. I assume I use the $arg and $taxonomies from my custom post type rather than the ones you have listed.
Ok, but please don’t forget to include the link to my blog somewhere in your plugin about page.
Thank you so much! amazing!I got it to work the first time.
Hi,
this code works smooth and so easy to use :)
I just have one thing.
It I duplicate a post which includes a gallery, than the items not visible in the copy at “Create Gallery > Media Library > Uploaded to this post”. It shows “No items found. Drop files anywhere to upload”.
Of course, it shows the items in general, just not listed in the dropdown filter “Uploaded to this post”.
It’s possible to “fix” it?
Cheers
Jingz :)
Hi,
I’m not sure this is possible, because each attachment can only have one parent post.
Hey pal, thanks a lot… I was ready to install a plugin but am one of those who prefer the less amount of plugins possible.
I’m gonna repeat the jingz question. Aren’t images related to the posts by slugs into the db? Can’t I relate the same image files to the duplicate post with different slugs? I mean… WP will automatically create new slugs when I try to insert the same values to the table, no?
How do the featured image duplication works? Isn’t it what we are expecting?
I’m using it in a bilingual blog that shares all the same stuff, custom fields, tags and category. Only title, slug and content is different from one sibling post to another. So doing this image linkage automatically would be beautiful.
One more question, do I get the relation between both posts on-the-fly, in a way I can print the duplicated post and tell who was the original one?
Congrats for your work, it saved me immensely.
Hi,
This plugin copy the featured thumbnails but don’t save the image relations to the post.
It don’t duplicate the images as well.
Yes, you can save the original post ID as new post custom field value.
Alright, I’ll see what I can get. Thanks!
This is a great function. I was wondering is it possible to remove the default category. Everytime I do a duplicate, it populates the default category too.
Thanks for contacting. This bug is fixed.
Hi
Misha, the post images are not duplicating when i use your code.Can you give a solution for duplicating the post gallery
Hi!
do you mean images, attached to post? Then you should also include the loop with duplicating all post children (post type attachment).
Am I missing something? Where is the loop you speak of that I need to include so that I may copy the image attached to the post?
This works only for posts and not for pages even if we change the last line of the above code.
Please check or let us know the exact code to duplicate pages.
I’ve just tested it. It seems like everything is ok with pages.
Worked the first time. Awesome function. Thanks!
Brilliant! Many many thanks for sharing your superb code, Misha (including your very helpful comments). It does exactly what I wanted and will save lots of time in creating pages.
Hello Misha,
I’ve succesfully used your code on a custom post type I’ve created. But suddenly, it stopped working. I’ve been thinking why it stopped working, and I don’t have a clue.
I’ve tried disabling/deleting plugins. No luck.
Then I tried enabling/disabling it on other custom post types I’ve created in the same theme. The strange thing is: when I enable it for the standard ‘post_row_actions’, it shows on one of the custom post types. But when I enable it specifically for this custom post type like so ‘vragen_row_actions’, it doesn’t work.
As for the other custom post types: it doesn’t work anymore at all.
Do you know what could be going on?
Hello, Kevin,
the solution is in this comment.
Misha
Great snippet of code! Thanks so much. I’m having the same problem as Kevin above… using ‘event_row_actions’ doesn’t work, but if I use the generic ‘post_row_actions’ it was, albeit for all posts, which is what I’m trying to avoid.
That said, I can get around that by check post type in the function itself by add ‘($post->post_type == ‘event’)’ to the if statement.
—-
My second question is about the redirect… Since I’m using this for an events plugin, I’d rather not redirect the user to the post edit screen. I would prefer that the duplicate post is created, saved as a draft, and the user remains on the list view page. They could then click quick edit to simply change the date of the event since thats all that changes.
I tried just commenting out the wp_redirect() line but this still tried to redirect the user and produces a blank screen.
Any thoughts on how to accomplish this?
Any help is greatly appreciated.
Hi Bruce,
the answer to you first question is here,
as for redirect — just change this line of the code
to
hey!
first of all, thanks!
second – can you write the filter for duplicating portfolio items?
thanks alot!!!
tslil
Hey,
here it is
SWEET bit of code! – Saved me a bunch of time, a bunch of times!
Cheers x
Misha, this is such a great solution. Saves me tons of time when I’m creating dummy content and it already includes taxonomy and meta data. It’s perfect! This will be a huge time saver for admins/clients too! Thank you for sharing this!
Thanks for a simple, effective method to duplicate posts! most appreciated, worked like a charm.
If I have portfolio content type, how would I use this code to do something similar. Is there a way to modify this easily?
Hi Gene,
look at the solution here.
the solution link above just refreshes this page. Is there another place to find the solution to duplicate portfolios?
Hi Sam,
sorry for that – I will fix it, for now just search for my comment on this page from “October 16, 2015 at 17:10”
I added your duplicate post code to my web page:
http://easywebdesigntutorials.com/an-easy-way-to-duplicate-posts-or-pages/
Have a great day!
Thank you for the snippet!
Have you thought about creating a WordPress trac ticket https://core.trac.wordpress.org/ suggesting that duplicate post is added to Core?
Have a great day too, Paal!
No I haven’t :) I’m not sure they need it.
Fab! Works perfectly! :)
Thanks so much!!
I hate to be the bearer of bad news, but this is WIDE open to hostile SQL injection and you fail to sanitize any of the GET/REQUEST variables with absint() and such like you should. I could drop your tables/database in a couple of characters on any site that uses this.
Outside of that it looks rather helpful so thank you for posting :)
Thank you Jeff, I’ve fixed it.
For some reason, the meta data never would copy for me, so I replaced your “duplicate all post meta” section with this, and it seemed to work like a charm:
This is very simple. Thanks.
Yes very good. Thanks Misha and Corbin ;-)
I was just coming here to say something similar but you beat me to it :) Nice solution.
Hi.. I try this code in my local host.. and try to write with duplicate.. but the Link was numbered and still publish..
any ideas for it or it’s not work in local host ?
thanks
Hi,
Duplicate link only appears on the all posts page (near the Quick Edit link).
Is there a way to just duplicate the featured image? Instead of copying all meta information, the only meta I want is the featured image. How would I go about that?
Thanks
I think it will be enough to copy the meta with
_thumbnail_id
key.So how would I rewrite the following code to just duplicate the
_thumbnail_id
key? Sorry I’m not really a database guy so I’m not too familiar with how to handle queries.Thanks
I hope it helps:
Nice. Thanks Misha.
I have two custom post types, “Books” and “Author”. I want to get the plugin to duplicate from one post type to the other. So in “Books” I have a post called “Moby Dick” instead of “Duplicate Post” I have “Author details”, when I click “Author details”, it will duplicate the “Moby Dick” post to my other post type “Author”. Under the “Author” post type I will have a new post called “Moby Dick – Author”.
Is that possible? Thanks in advance.
Yes, it is possible, please contact me via email.
Hi, can you post the solution, i want to change the post type whil duplicating.
Thanks in advance.
Hi Jakob,
just set the preferable post type on line 51 :)
Hi Misha,
thx for the quick reply, but it did not seem to work for me.
Does still create a post_type product.
Hi Jakob,
I made tests with converting
post
topage
type and everything works for me.The code duplicates posts and custom post types well but I am unable get an metapostdata to copy across?
Thanks for your help
Hi,
please, try this.
Thanks Misha
I tried Corbin’s code and it worked on a standard post – I added an excerpt and that was duplicated.
I need a bit more help if you guys have time. The theme I am using has what seems like the post type “Event” and this has extra meta fields, when I look at it in the database the post_type field is “event” – however, the duplicate link appears when this code is added:
and disappears if I change this to:
So I am not convinced that Event is it’s own custome post type? I’m getting confused.
Thanks for your expertise.
There are only two filters:
page_row_actions
— for page type,post_row_actions
— for posts and another custom post types.Ok, so I recommend you to make the following changes:
Hello,
This works great, however what if I am using a polylang plugin? I have a multilanguage site and when clicking duplicate it only duplicates the current language and not both languages. Any idea how to duplicate both language posts at the same time. They are somehow linked to each other but when clicking duplicate the post is duplicated however the link stays the same pointing the old post translation.
Thanks!
Hello, what polylang plugin do you use?
Hi MIsha, I setup a child theme, and also have a functions.php file in the child folder.
When I paste the code into the child folder functions.php, it does NOT work; when I paste it in the parent functions.php, it does work.
Is there a way to make it work in the child folder that I’m missing? Thanks!
Hi Troy,
I made some tests — the code works good with the child themes. I’m not sure where your problem is, please try to change filter priority here.
Genius Misha – that change from 10 to 9999 worked a treat for my child theme! Thanks for the time and effort. Great piece of code generously given :-)
Thank you Misha, You saved my life!
Thanks :)
Firstly, great code. It works out of the box.
What if I want a duplicate link/button on the page/post itself? Is that possible?
Hello,
do you mean post/page edit
wp-admin/post.php?post=2202&action=edit
pages?Hi Misha!
First, thank you! This is saving me a ton of time and is one less plugin to install.
Second, I think I am trying to do something similar to JJ Human’s question. I have built a site where all of the editing of posts is done through ACF forms on the front end. I am limiting access to the wp-admin pages to a few users.
I already changed wp_redirect() to redirect to the permalink of the new post. This isn’t working. Right now it redirects to a blank version of the original post.
Is there anyway to execute this code to redirect to the front end version of the website?
Thanks so much!
Jess
UPDATE: I figured out how to publish the post and redirect it from the admin link. Turns out I was using an invalid post status.
Now I just need to create a template tag that will create a link to do the same thing on my single.php page.
Hi Jess,
I think this comment could help you.
Thanks! I refuse to install any more plugins for these small things:)
Works perfectly:)
Hi. I just have tried it and it looks great.
I simply want to thank you, Misha and other contributors, for sharing the code and especially for the willingness to help and collaborate.
I also have few questions, possibly naive since I am not a deep technical guy in php and wordpress:
1. If I append your code in my php (I have other code already there) it won’t execute. If I prepend it (as the first block of code in the file) then it works fine. I assume there would be no restriction on where I place the code inside the file, right?
(I ask that because I then suspect I have some errors in my pre-existing code :-|
2. Though I could not find it explicitly stated, I assume I can have both filter working at the same time:
It seems to work for me, so that I can have the “duplicate” option both on posts and pages at the same time.
Or was it intended to have just one filter active at a time?
Thanks a lot!
Hi Cristiano,
yes, there are no restrictions of where you placing the code, maybe you place it incorrectly after the closing
?>
tag.Yes, you can use both filters at the same time :)
Hi! I just added this to my blog and it works fantastic!
One question though, the page views for the posts are also duplicated so it didn’t restart at 0 (and I won’t be able to get an estimate of how many people have viewed my new post).
Is there a way to reset the page view of the new duplicated post to 0?
Thank you for making my life easier :)
Hi Astrid,
try to add this:
I’m happy that I can help, you’re welcome :)
Thank you! Worked like a charm :)
Quick update, the solution didn’t work anymore after I updated my theme so I tweaked it to:
and it works again :)
Thank you ^^
Ok, it looks like the meta key name has been changed in the new theme version. Great, that everything works now :) Thanks for sharing.
Excellent!
I’ve been using a post duplicating plugin for a while, and I think it has royally screwed my SEO. The duplicator also duplicates the meta data, so it won’t let me push the cloned posts out (as a new post) to social media. Is this also something I can control as a code level, as easily as the above?
Thanks for your thoughts.
Hi Kelley,
I’m not sure that I understand your question.
So, do you want to prevent the duplication of the meta data?
Sorry for not being clearer, Misha. When I use a post duplicating plugin, I can’t automatically push the cloned post out to social media via Jetpack. Jetpack reads the meta data of the original post; therefore, it won’t recognize the cloned post as an original, to be pushed out to social media upon publishing. If I duplicate a post by using this code modification, will I be able to push cloned posts out as new ones using Jetpack (or another publicizing plugin)?
Thank you!
Ok, now I understand your problem.
Some thoughts about it:
1. Duplicating posts won’t increase your SEO, it may bring you the opposite effect I think.
2. On the official Jetpack website is said that Publicize never will be triggered for the cloned posts — I don’t know how it checks it — you can try to clone post without meta data for a first time and look at the effect. To turn off copying meta data, remove from the code lines 67 – 77. If after that the post will be pushed to social media, then everything is left to do for you – just to find out what meta data keys to clone.
Thanks this is just what I needed
Very nice, huge help. Thank you!
doesnt work in WP 4.6
Hi Jay,
everything is ok for me on WP 4.6.
Works perfectly with 4.6 for me.
Awesome!
Thank you so much.
Thanks for this nice script.
you should use a prepare state for the SQL statment, but adding “(int)” to this should make it a bit saver to:
Just to make sure the page is not locked when someone is using it when you make a copy:
Hi Tim,
Does it create a draft or it it doesn’t create anything?
Thank you so much for this post. Super helpful.
So helpful, TNX!
Absolutely wonderful, simple and complete solution. Thank you for sharing.
Hello,
What a nice script ;) I have successfully integrated it with every improvement of this comment thread. But I really want to expand it to fit my needs, and I require some help in order to achieve this.
What I want to do is to create 2 new “duplicate link” in order to have a “Duplicate” link, a “Generate the news related article” link and finally a “Generate the forum article” link.
Why have I these needs? Cause for each subject of my website, I have 2 related articles with the same meta, taxonomies etc… only the title and the content will change. If I publish a post named “Photoshop”, I’ll create just after this 2 others related posts “News – Photoshop” and “Forum – Photoshop”.
My question now : how can I achieve this with a single function? I can actually make 3 different functions for the 3 “duplicate link” I want, but this will makes unnecessary request.
These 2 additional duplicate links must change the title by adding a prefix (‘News -‘ and ‘Forum -‘), and erasing the content (kinda easy, just delete the line from the $args).
If someone can help me to achieve this, I’ll really appreciate this.
Hello,
it is enough to use one duplicate link – you just need to just need to run the code inside a function 3 times :)
Hello,
I’m not sure to properly understand. The variable $args are different for the 3 links… I can’t figure out how I can run the code inside the function 3 times.
Hello,
I understand you clearly – of course you can not just copy and paste this code three times :))) It requires customization. If you contact me by email I will help you with the code.
Contacted yesterday via your email, just waiting for an answer ;)
please check your junk folder :)
Great post and still valid over three years later :) Thank you.
Just a heads up if anyone else comes along here and have an issue where if you duplicate a post, edits it but keeps it in draft mode and then checks the original post in the frontend only to see that the content of the original post seems to have been updated as well.
This seems has to do with the fact that
post_name
of the new post gets set to the same value as the original. I solved this by simply removing the line'post_name' => $post->post_name,
(40 in the example code at the time of writing this). This sets the post-name to a “slug version” of the title (which, even though it is set to the same as the original post, will be changed by WP when wp_insert_post is executed).Thank you for your comment! :)
Bjorn: Thanks man. Was driving me insane why “drafts” seemed to affect the published post from which it was first duplicated from.
Misha: Million thanks for the initial post. This really will help save Client headaches ( or at least mine when teaching them how to post on their new website ).
+1 on this! Thank you!
Misha-san, thanks so much! I just tried and worked like a champ. Saved my time!!!!!
Thanks! This is great!
Hi Tim,
Did you get it working? I have the same need. New to WordPress and php. Help is greatly appreciated. Thanks!
Man, Thanks so much –
Was able to break this down into a new_user script that duplicated a series of complex custom post-types, by just passing it the old post_id and the new author_id.
Absolutely clean.
New User account created and their front end list of Posts that they can modify are the sets of cloned pages.
Dream
Thanks
What if I want to duplicate a page like how Apple does for different regions?
Example:
– apple.com (US)
– apple.com/sg (Singapore)
– apple.com/ae (Middle East)
Can it be done with some sort of a splash screen? When the visitor goes to website.com, there is a pop-up with option for their desired content, and it directs them there?
Thanks in advance for those who will! :)
Hello,
A splash screen is the whole theme for a different tutorial :)
This easily worked for me in WordPress 4.6.1. Thanks for sharing this.
Thank you! It works great! Is possible to exclude one or two meta keys?
Hi Christopher,
please sorry for such a delay in replying.
You can easily exclude two meta keys by adding them into the SQL query on line 67.
Hi
What about if we want to have checkbox in edit post section with this function?
Thanks!
Hi,
could you please give me more info about how checkboxes should work?
Hi Misha thanks for your replay!
First it can be simple metabox with just one checkbox “Would you like to duplicate this”
if you check it will be duplicated only when it is published once.
Could we change the code to copy to specific category and to leave all other taxonomies ?
Regards!
Hi Nikola,
I think yes you could, try to connect this code to
save_post
action hook.So in the function connected to
save_post
you need to check if checkbox value == “on”, and if yes – run the duplicate function.Hi, thanks for the script, it works well, however I need to exclude a custom field which is providing a unique ID to each custom post.
I have added an ‘if’ clause to exclude my specific field and it seems to work:
Seems to work for me, but perhaps there is a better way?
Hi Ben,
if it works – use it,
you can also try the code from this comment.
Thanks!
THANK YOUUUUU
Awesome function.. Thanks!!
Is this still working on the latest version of WordPress 4.7.1?
Hi Jordan,
yes, of course.
Please, guide me further on in the article editing
Good job, thanks!
Of course, you MUST add a nonce to the link and the nonce verification on the action handler!
Thanks for mentioning this. 100% agreed with you.
Nonce verification is added.
Thanks, that worked beautifully and took < 1 minute.
Wow you are awesome…. Googled -> Copy Paste -> Voila :D
Question, somebody can please help me, i want to remove the duplicated posts link with original post. For example I remove the old post the URL of the old post redirect to duplicated post.
I hope you understand, it is something related to _wp_old_slug meta key. But I did not understand how to stop it.
Hi,
can you describe it in details? It is still not 100% clear for me.
I’ve updated the code with this line:
Please try it now.
1. And in case that we need to exclude multiple meta for some more meta filed ? :)
2. And how we can change category?
For example to duplicate always to same category
3. How we can duplicate attached featured image?
Regards
1. Use
||
in yourif
condition.2. Replace the part of the code that duplicates terms with the only one function:
and pass your category slug/ID there.
3. I have no ready code for that, but if you find a solution, please, share the code in comments here :)
2. but in this case it doesn’t copy tags :(
I think he mean if you change title of post, than use duplicate function it will copy meta field with old slug.
When you delete original post, wp will keep redirecting to duplicated post because of old slug meta field
Regards
Thanks so much! Saved hips time :)
BR
Hello ,
This is a great code , I am using this code in my functions.php
and it applies to all posts, custom posts , pages by using (page_row_actions) , But i have event post type and there it is showing two times Duplicate option with one duplicate publishing it as well while other duplicate option keep it as draft , What is the reason for this . how can this be solved ? And will this code applies to all the custom post automiatically?
Hello. Is it possible to let this code work with front-end user profiles without need of access to dashboard?
Hello,
My code is only for dashboard, by try Tim’s code.
You are awesome you save my tons of time..
Thank you have great job…
Great code here, Could you possibly help me add the ability to duplicate all the posts children as well? willing to pay.
Hi,
The Clone link doesn’t appear for Marketpress products. Are you able to fix?
Cheers,
Johnny
Hi,
Maybe these comments will help you.
I have got the code running using my functions.php file.
Now when I click ‘Duplicate’ in my custom post type list, it will white screen of death.
I then check the drafts and there are no new posts.
What do I do now?
Cheers,
Johnny
Open your
wp-config.php
file and turn onWP_DEBUG
– it will show you where is the error.My issue was I forgot global $wpdb;
Hi,
good solution! I have two wordpress, in the same server. WordPress use two database with same data. How I can setup the destination database before wp_insert_post? If it’s possible, I can use this plugin to duplicate post between two wordpress (i.e from staging to prod env). Thanks!
Hi,
I have no idea unless you’re using these websites within a multisite network.
Great ! Up to the Mark.
Thanks for this; was looking all over the place for code to do this simply. Will be trying this out tomorrow. :-)
Thanks so much for this! Really appreciate you sharing your solutions with the WordPress community at large. Saved me from downloading yet another plugin.
I’m happy to help π
Always welcome!
Also, thanks for being so thorough with your comments! Incredibly useful as I’m trying to learn more PHP and WordPress programming. Went through your code line-by-line with PHP docs and codex open right next to it. Learned more just reading through this than I have anywhere else.
Thank you too for sharing this! π π
I have website A and B. website A is current website. Website B is a new design of the website A.
its a news portal. we publish 150 articles daily.
we are now live for website B. posts from website A was migrated at 3 days ago midnight.
now we need to update the posts from Website A to Website b for the past 3 days of posts.
how can we do this without a wp plugin.
Website A > WP 4.9.
permalink strucure : xxx.com/%category%/%category%/xxx
Website B > 4.8.2
permalink strucure : xxx.com/%category%/xxx
I recommend you to learn about REST API.
Hi,
The link for custom post types doesn’t works.
What is the date of this comment ?
Hey Martin,
Custom post types were tested many many times π
I’m still not sure where was the problem for those guys who can not make it work for CPT.
It’s the actual link in the post itself above i.e. ‘this example’ that’s not working…
For custom post types view this example in comments.
You can use several filters at the same time, of course.
Thank You Misha.
Hello
Is there option to duplicate one post n times. For example if I create one “template” post and I wish to duplicate it 200x? Can I do that in one step, I do not wish yo click on “duplicate” 200 times?
Thank you.
Hello,
Wrap 55-85 lines in a loop.
Thanks that really help me for my portfolio plugin. Did not need to change much of the code
For custom post types view this example in comments…where? ;-)
There is a link under the “Comments” title, it allows to view the previous comments π
No, it doesn’t work, please leave a link
hi, you keep referring to a comment here that doesnt exist. I dont understand why you would do this.
its bad enough trying to learn and do these things without being given the code, it would take 5 mins to update the post, instead you are misleading people.
if you can take the time please let all of us know the solution for custom (or any/ all ) post type please.
thanks
J
Hi,
I tested it many times and it works for me for CPT.
Please contact me by email and I will try to figure it out why it doesn’t work for you.
It’s ok sorted it out thanks mate.
What was the problem?
Good tutorial for copy page because sometime it need to clone same layout from one page to another and it will very helpful for it and also able to copy page layout via making it duplicate thanks for informative article
really your are awesome man.Thanks for save many developeers time.
This is great! Thanks!
Very nice! It works! Thanks
Great tutorial! This was so easy to follow and exactly what I was looking for. This is a beautiful tutorial. Good job and well explained.
Thanks.
Great code, thanks!
I would really like to have it work for my custom post types as well, but following the link in the last paragraph of the article didn’t get me to the comment in question. Could you please correct the link or maybe paste the code snippet again?
Never mind, just figured out how to customize the code you wrote to filter pages in a way that it works for my custom posts.
Thank you anyway, great tutorial! :)
I’m glad you’ve figured it out :)
Misha, thank you for this. However, when I try to insert into my functions.php, it gives me a syntax error, unexpected ‘if’ (T_IF) on line 197 (which is line 13 of the code you posted). How to fix please and thank you?
Hey,
Everything seems OK on line 13.
Hi Misha,
why do you use
wp_get_object_terms()
and notget_the_terms()
?Thanks, Fred.
Hey Fred,
get_the_terms()
returns objects, but I need slugs only.I just wanted to say a big thank you, I love your code, beutiful format and well commented.
This was really helpfull, i would suggest though that you add in how to enable this across custom post types. As the #comment link does not work!
It’s easy enough, but i think people will struggle if they don’t have the coding knowledge.
Hey Aaron,
I tested it at least 3 times β works perfectly for custom post types. Have no idea what happens for those, who can not make it work for CPT.
Oh I see :)
What makes this confusing is the final comment that’s suggesting that they need to make a change by following a comment in your closing statement.
Again thanks for sharing this beautiful code, it works perfectly
Thank you so much, Misha. This is incredibly helpful!
THANK YOU! YOU’RE A LIFESAVER!
I do not even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you’re going to a famous blogger if you aren’t already ;) Cheers!
Thank you for sharing this, great code snippet – just need a bit of tlc ;)
Thank you for your comment. By the way what tool are you using to display these warnings?
So, let me explain, we have only three input parameters βΒ post, which is a number and it is passed through
absint
function on line 10, so it is OKduplicate_nonce it used only to check nonce, nowhere else, so it is OK
action is also used only to check if it is equal to the string rd_duplicate_post_as_draft, nothing else.
So, everything is ok! Let me know if I’m wrong π
Thank you, you saved me hours of work! :)