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.

48 Responses to “WordPress Copy Post Plugin”

  1. 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. 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/

    • maria says:

      now, where can i find step by step instructions? i have the copy post plugin loaded on the source server….how do i get the posts to copy over to my new blog?

  3. 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.

    • 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 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 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

    • 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 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 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

    • 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 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 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..

          • 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.

        • 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 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 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 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 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 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. 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 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

    • 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 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!

    • 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 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 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?

    • 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 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

    • 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.

  17. Doug says:

    Help. After hours of configuring, I keep getting:

    ERROR: Author () does not exist on target system!

    Note that the parentheses are blank.

    But I am definitely sure that both blogs have an author named Staff.

    So why is it blank, and why the fail? Is it WP3.01?

    You said at the top of this page above:
    “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.”

    What do you mean by author, login, and ID?? Do you mean Administrator? I am using that, not an Author, but the nickname is Staff.

    By login, do you mean Username?

    By ID, do you mean password?

    Thanks!

    • Jeff W. says:

      Hi Doug,

      Sorry for the long delay, things have been pretty busy over here.

      I tested the plugin with WordPress 3.0.1 upgraded from 2.9.x and also cleanly installed. Both worked, so the WordPress version doesn’t seem to be an issue.

      With the error you’re getting, does it have the title of the post you are copying in the line above the author error? It should tell you this, regardless of any other problems it may run into. The page should say something like:
      Target blog: http://wp2/
      Copying post: fred’s post
      ERROR: Author (fred) does not exist on target system!

      The plugin should be installed on the blog that has the posts you are trying to copy (the source). You should configure the plugin via the Settings > Copy Post menu in the Site Admin. You enter the URL and database information for the blog you are copying to (the target).

      On the source blog, go to the Edit Post page for the post you want to copy. In your browser’s address bar your URL should look something like “http://wp1/wp-admin/post.php?post=4&action=edit”. The Post ID is the number between “post=” and “&action=edit”, so in this example the Post ID is 4.

      Go to the Copy Post page in Site Admin, enter “4″ into the Post ID field, and click Copy Post. It should tell you what post it is trying to copy.

      There needs to be a user with the same username (login name) on the target blog. The email address, first/last name, or role don’t need to be the same. In your case I think this would be “Staff”.

  18. Doug says:

    Do you ever answer posts? Please?

  19. David Wells says:

    Jeff,

    This plugin is absolutely amazing!

    Is there any way to automate the plugin to run each time a post is published?

    Many thanks!

    • Jeff W. says:

      Hi David,

      With a bit of tweaking, I’m sure you could get it to run when a post is published. We wanted to selectively pick notable posts from our internal blog to share with everyone, so we didn’t set it up to run automatically.

      In a nutshell, here’s the changes needed.
      1. Refactor/move the bulk of the copy_post.php code into a function so it can be run manually or automatically.
      2. Use add_action() to hook this new function onto the “publish_post” action.

      Hope this helps.

  20. David Wells says:

    Jeff,

    I am also trying to get post_meta to transfer as well.

    How might I go about doing this?

    Thanks

    • Jeff W. says:

      Hi again,

      You could extend the plugin to fit your needs. From a quick look at the WordPress database description, copying wp_postmeta should be similar to copying comments. If you’re comfortable with PHP and some SQL, copy_post.php line 148 would be a good place to start.

  21. Denise Barnes says:

    Where is it that one configures the plugin? I have installed it and network activated it, but when I try to go to the admin area, I get only:

    Copy Post
    Please configure this plugin before using it.

    Thank you.

  22. Prashanth says:

    Is the plugin compatible with WP 3.1.1 ? I am getting this error

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘destination_wrdp1′@’123.456.789.123′ (using password: YES) in /home/myblog/public_html/wp-content/plugins/copy-post/copy_post.php on line 39

    Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/myblog/public_html/wp-content/plugins/copy-post/copy_post.php on line 40

    Warning: mysql_set_charset() expects parameter 2 to be resource, boolean given in /home/myblog/public_html/wp-content/plugins/copy-post/copy_post.php on line 42
    Target blog: destinationwebsite.com/

    When I enter the Post ID and Click Post – I get this error

    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/myblog/public_html/wp-content/plugins/copy-post/copy_post.php on line 72

    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/myblog/public_html/wp-content/plugins/copy-post/copy_post.php on line 61
    ERROR: Author (AuthorName) does not exist on target system!

    But, I have the same author on the destination blog? Please help.

    • Jeff W. says:

      Hi there,

      “Access denied for user ‘destination_wrdp1′@’123.456.789.123′ (using password: YES)”
      This error means the database information you entered for the destination blog isn’t correct or the database user you’re using isn’t allowed to connect to the database. Check that you’re using the right username.

      • Prashanth says:

        Hi Jeff,

        Thanks for the quick reply..

        I have check it and user name, permissions and database name is correct. and I still I am getting the same error.
        But, I have noticed some thing strange – The error that we are getting for @123.456.789.123 – Remote Host is different from what I configured ? In other words my remote host is 123.456.987.321 and in the error message it displays as “Access denied for user ‘destination_wrdp1′@’123.456.789.123′ (using password: YES)” ?? As you can see, the remote host ip is different in the error message. Is this normal ?

        Please help.

        • Jeff W. says:

          The remote host in the error message is the IP address of the webserver running your source blog, as seen by your database server. This is likely different than your workstation. You need to ensure that the user destination_wrdp1 is allowed to connect to the database from the webserver.

          • Prashanth says:

            Thank you very much for the reply.

            So, how can we ensure that destination_wrdp1 to connect from webserver ? Is this done via cPanel ? & How ?

            Please help

          • Prashanth says:

            Yeah!.. Its working now.. Awesome. Thank you very much for all your help.

            Kudos to Jeff.

  23. tbk4040 says:

    Hi
    Would appreciate some help please…
    I’ve installed the copy post plugin on site1 trying to copy the blog articles to site2.
    I’ve put the settings in as per the instructions on this blog and checked them iwth the wpconfig file – they are correct.
    The same user is on the site2 user list.
    And yet i get the single error line:
    ERROR: Author (name) does not exist on target system!
    What am I doing wrong?
    Wordpress edition 3.1.3 is in use on both sites

    Many thanks
    TBK

  24. Anders says:

    Hi tbk4040 and Jeff,

    Did you ever manage to fix the “ERROR: Author (name) does not exist on target system!”?

    Sounds like an excellent plug-in, however I get the exact same error message here on WordPress 3.2.1.

    Any ideas?

    All the best

    Anders

  25. Felipe says:

    For those who cannot install
    this error occurs
    IF the database is wrong, if the user doenst REALLY exist
    note that the name of the username must be the same as the POST CREATED on the source, and the POST ID MUST BE ONLY THE NUMBER

Leave a Reply