WordPress Copy Post Plugin

Have you ever been in a place where you’re maintaining two blogs and want to copy posts from one to the other? I wrote a WordPress plugin that does just that.  In our case it copies from Dayspring’s internal blog to our public one.  This removes the tedium of having to copy content, comments, and tags manually.  It also preserves the original post author and date.

First, a few assumptions and caveats.

  • The author of the post you are copying must have an account on the target blog with the same login name, though the IDs don’t have to be the same.
  • Categories assignments are not copied over, mainly because in our case the categories on the two blogs are different and there isn’t a clear mapping from one to the other.
  • Comments attributed to registered users retain this attribution only if the commenter has an account on the target blog (just like the author).  If the commenter doesn’t have an account, the comment is still copied, but it’s treated as if it were made by an unregistered visitor.

Use the copy post feature to send a post to a target blog.  You’ll need the post ID, which is available by looking at the edit link for the post.  The plugin will copy the post content, tags, and comments.  The original author and post date will be retained.  All category information will not be copied over.  The resulting post will be set as a “private” post so allow you to set the categories and make edits before it goes live.  Also, you’ll need to be an admin on the source blog to use the plugin.

The settings for the target blog are configured directly in the WordPress Admin interface, making it possible to install and configure the plugin without needing to edit any code.

You can find this Copy Post plugin in the WordPress Plugin Directory.

29 Responses to “WordPress Copy Post Plugin”

  1. Blogger 101 Blogger 101 says:

    I am very interested in this plugin as I need to move blog content often. I coudn’t find it on Wp, please let me know where is available.
    Thank you

  2. Jeffrey Wong Jeff W. says:

    Blogger 101: I’ve submitted the plugin to the WordPress plugin directory. You can find it here: http://wordpress.org/extend/plugins/copy-post/

  3. Marko Marko says:

    After activating this on a wp 2.8.4 / php5 installation, I wanted to go to the settings page of the plugin, as per instructions, but I got a 404 error.

    But even if it did work properly, i don’t see why the plugin would need direct access to mysql? You’re already logged on, with all admin-functions available.

    • Jeffrey Wong Jeff W. says:

      Marko: Looks like I had a bit of trouble in packaging the plugin for distribution. I’ve corrected the directory structure which should resolve the 404 error you were getting. Update to version 0.2.0 and give it another try.

      The plugin needs direct access to the destination blog’s MySQL server. This plugin is for copying a post from one instance of WordPress to a separate instance of WordPress. It is not intended to duplicate a post on the same WordPress instance. Yes, the plugin has access to the source blog since you’re logged in, but it needs access to the destination database. The destination database might be on the same server as the source database or it could be on a server located halfway around the world (or even halfway across the galaxy if you could get an internet connection out there).

  4. Alberto Alberto says:

    Hi Jeff!
    Thanks for your great job! It save my life!
    Just one question: is it possible to copy more than one post at time?
    Putting a comma between ID’s ?

    Thank you.

    Alberto

  5. Gabriel Gabriel says:

    Can you help me through the Options… I am definitely not internet saavy but I own everything on the blogs so, please tell me hoe can a have the data needed configure the blog.

    Do I need to install the plugin in both blogs or how does it work, do i install it first in the one with the original post?

    Options
    Remote Blog URL (ex. http://blog.dayspring-tech.com/, including trailing slash)
    Remote Database Host
    Remote Database User
    Remote Database Password
    Remote Database Name

    • Jeffrey Wong Jeff W. says:

      Hi Gabriel,

      The remote blog is the WordPress blog that you are copying a post to, the plugin only needs to be installed on the blog that has the original post. You also need to be able to log into the MySQL server of the new blog.

      Remote Blog URL: The URL of the new blog.
      Remote Database Host: The hostname or IP address of the MySQL server for the new blog. This might be the same as the DB_HOST from the new blog’s wp-config.php file. Unless the original blog and new blog are on the same server, this shouldn’t be “localhost”.
      Remote Database User/Password: Username and password for the MySQL server. You can probably use the same user as you have in the new blog’s wp-config.php file.
      Remote Database Name: Use the database name that is in the new blog’s wp-config.php file.

  6. Daniel Daniel says:

    Nice plugin! Just what I was looking for. I am combining several small blogs into one to be more efficient. Will you add category matching in a future version?

  7. Paul Paul says:

    Hello,

    Great idea for a plugin. I’m currently trying to get it to work and I’m running in to a problem. Whenever I try to copy a post I get an error saying the user doesn’t exist on the other blog but I know that they do.

    Do you have any ideas why I might be getting that?

    Thanks,
    Paul

    • Jeffrey Wong Jeff W. says:

      Hi Paul,

      The plugin looks for a user with the same username, but the user ID’s don’t have to be the same.

      • Paul Paul says:

        Hi Jeff

        Thanks for responding! It turns out that the problem was I have non standard table prefixes, so instead of ‘wp_posts’ I have ’something_posts’. I updated the code in the plugin to use the non standard prefixes and it worked.

        Is there a way to copy the post attachments over as well?

        Thanks!
        Paul

        • tech tech says:

          I keep getting ERROR: Author (name) does not exist on target system!

          I have verfied both usernames are identical but yes the source blog has non standard table prefixes how can i edit the code to reflect this?

          Basically instead of wp_posts it has wpi9_posts etc etc..

          • Jeffrey Wong Jeff W. says:

            Hi,

            The table prefixes of the source blog should be handled by WordPress’ own database functions. However, the target blog table prefixes are expected to be the standard wp_. For now, you’ll have to edit the copy_post.php file to change the target blog table prefixes.

        • Jeffrey Wong Jeff W. says:

          Hi Paul,

          I’m glad you were able to figure out what was going on and solve your problem.

          We didn’t have many attachments, so we opted to manually transfer the few we did have instead of adding the feature to the plugin. I hope the plugin still provides you some value even in its basic form.

          • tech tech says:

            Hello
            Yeah i just checked target blog and its standard prefixes too And i fixed by changing target host as localhost and not domain name…not sure if that what the problem was but it worked.

            Thanks

  8. ibrahim ibrahim says:

    Hi there,
    May i know that how do i find the post id from my source blog to destination blog? like what is the post id and which type of value it is?

    • Chi-Ming Chien Chi-Ming says:

      On your source blog, when you’re in the admin backend, find the post you want to copy and “Edit” it. The URL in your browser’s address bar will then display the Post ID:

      Example/ If your URL says:

      /wp-admin/post.php?action=edit&post=1234

      the post ID is 1234

  9. Enrico Enrico says:

    Hi,

    I keep getting ERROR: Author (name) does not exist on target system!

    I have verfied both usernames are identical and have the same standard table prefixes between the 2 blogs “wp_”.
    Can you help me, please?
    I work with WP 2.91. Thanks
    Best,

  10. jshapan jshapan says:

    Just like others above, I keep getting ERROR: Author (name) does not exist on target system!

    I have verfied both usernames are identical and have the same standard table prefixes between the 2 blogs “wp_”.

    How do I fix this????

  11. Jeffrey Wong Jeff W. says:

    Enrico and jshapan,

    I tried with two vanilla installs of WP 2.9.2 and didn’t get an error. Are you using the same version of WP on both blogs?

    Are you getting any MySQL warnings before the error? Also, double check that the Copy Post settings you entered are the same as in the wp-config.php on the remote blog.

  12. Megan Megan says:

    Hi

    I’ve installed the plugin on Site A and have entered the details. When I add a new post I don’t get any errors and the post displays as it should on Site A, however it doesn’t appear on Site B.

    I am fairly new to all this so assume I’ve done something/left something out. Do I simply install the plugin and then do the settings and it should work?

    Thanks

    Megan

    • Jeffrey Wong Jeff W. says:

      Hi Megan,

      The plugin isn’t completely automated, it requires you to initiate the copy. After you’ve posted on Site A, go to the Admin dashboard of Site A. In the left column you should find Copy Post. Enter the ID of the post you just made and click the button to copy it to Site B.

      We didn’t want it to be automatic since we use one blog internally within Dayspring and didn’t want our internal notes getting posted to the internet.

  13. Gillian Soh Gillian Soh says:

    Hi Jeff,

    I have created multi-sites thru the Network function. All the content sits on the same database.

    I need to copy the post from Site 1 to Site 2.

    I tried using the Copy Post Plugin but it prompt me the error msg “ERROR: Author (XXXXX) does not exist on target system!”

    Is there an way to resolve?

    Thanks!

    • Jeffrey Wong Jeff W. says:

      Hi Gillian,

      Are you using WordPress 3.0? We haven’t updated the plugin to work with 3.0. This will probably happen when we upgrade our blogs to 3.0.

  14. T Maxwell T Maxwell says:

    Hi, I’m trying to copy existing posts from our live site BACK to a localhost on my laptop (to experiment with some different themes, etc.). Try as I might, I too keep getting the ERROR: Author (xxxxxxx) does not exist on target system! message. I’ve done all the checks mentioned in the above posts. Is there any particular change I need to make because I’m copying to a localhost? Thanks. (I’m using xampp, username is root, no password and I’ve created a custom database name and folder on localhost.)

  15. T Maxwell T Maxwell says:

    Just one other clue: I just rec’d another error message when I tried to install a theme and I now wonder if I’ve made an error building my localhost site. Any advice? Here’s the message: “Unable to create directory /Applications/XAMPP/xamppfiles/htdocs/xampp/nameofdatabaseIcreated/wp-content/uploads/2010/08. Is its parent directory writable by the server?

    • Jeffrey Wong Jeff W. says:

      Hi there,

      In your case, the plugin should be installed on your live site instead of your laptop. The live server needs to be able to access the database installed on your laptop. If your server isn’t on your local network, you might be running into a firewall or router that’s preventing the server from reaching your laptop. The error from installing a theme probably isn’t directly related, but the uploads directory definitely needs to be writable by XAAMP or whichever user it’s running as.

  16. Michael Michael says:

    Hi Jeff!

    I’m interested in your widget. I somehow managed to bugger up my data base a bit because I installed a copy and replace widget on the whole site instead of just the content.

    The site still works fine as I can see but my google anayltic stats have dropped tremendously. I’m thinking i’m going to have to copy and paste my content into a new database to resolve the problem.

    You mention earlier that this widget copies from the data base after distribution. Do you think If i just copy my content using this widget it would resolve my issue?

    Thanks in advance,
    Michael

    • Jeffrey Wong Jeff W. says:

      Hi Michael,

      I’m not quite sure what you mean by “after distribution”.

      If you have a separate WordPress with a copy of your content, you can use this plugin to copy your content to the messed up site. If the copy/replace widget you used edited the content in the database (which it probably did), this plugin won’t be of much use to you. WordPress keeps content in the database, which is where this plugin reads from to create a copy and where the copy/replace plugin probably made its changes.

Leave a Reply