Serendipity to WordPress – Post import

The first thing you need to do in migrating from Serendipity to WordPress, is to move the post content. Luckily for all of us, at some point in time an importer was written (and shared). It has floated around the internet for a while and been updated a number of times. The version I used was verison 1.3, last updated by a German fellow. While his updates were good, I needed a little more out of it. Two pieces that were lacking were the handling of drafts vs published posts (John and I have a number of drafts, as has been previously mentioned) and the most important, matching up post id numbers. Without that one piece, you can’t move between the two platforms and maintain any links.

The first piece is easy, the second isn’t as much. WordPress doesn’t allow you to select your own post IDs during the post creation routine. Fortunately for you and me, there is a workaround, it involves a little bit of SQL, but anyone with the ability to READ and operate PHPMyAdmin (or command line MySQL), should be able to do this. So I’m proud to announce Serendipity (S9Y) importer for WordPress 1.4.

Please READ the readme.txt file. It is short and contains all the instructions (and SQL) you need. If you follow the instructions properly, you should be able to import a fair sized blog (~1000 entries/comments) in less than 10 minutes.

Update 2013-07-13: The plugin has moved from Google Code to a new s9y-to-wp repo on GitHub. Pull requests are always welcome!


Comments

  1. I am in the same boat as you were, and I love hearing that you were able to successfully move from Serendipity to WordPress – gives me hope! I started my site with Serendipity a couple of years ago, but over time I have grown tired of dealing with annoying work-arounds and other things (along with the non-working autosave you mentioned), so with WordPress 3.0 now released (I’ve been reading about it for quite awhile, including it’s absorption of WordPress MU), I figured I’d test it out and see if I could make the switch.

    I’m really glad to have found your work, since I’m not TOO technical of a guy. I have some questions, though:

    (I know that this was not created for WordPress 3.0, but I am hoping to discover that my problems are my error, so I don’t have to install a lower version and then upgrade.)

    1. I attempted to follow “Truncate (remove) all records from: `wp_posts`, `wp_postmeta`, `wp_term_relationship`, `wp_term_taxonomy`” but I received an error each time that told me removing all columns was not allowed and that I needed to simply drop the entire section. My mistake in misunderstanding the directions, or a WordPress version difference?

    2. After a few attempts, I figured I’d try and sidestep it, JUST to see if it might work. I was thrilled to see Categories import, and then Users, however, upon reaching the import for posts, I received this error… “Fatal error: Call to undefined function: array_walk_recursive() in /ROOT/wpTest/wp-admin/import/serendipity.php on line 419″

    I really hope to find an answer to these problems, so that I can move on to testing layout and design, and I appreciate it.. in advance.

    • Ah, I’m a bit of a boob. I noticed that it HAD been tested for WordPress 3, though I am currently running Serendipity 1.5.3, not the tested 1.5.2.

      Also, I have since discovered (another D’oh! on my part) the Empty option in the database, yet the error still occurs on import.

      • #1 – Sorry, I shall have to find the proper commands and clarify the instructions. By “Truncate” I meant “Delete all records”. All except for default category in `wp_terms`. You _shouldn’t_ have any records in any of these tables if you just installed WordPress – but I’ve seen it create a record in `wp_posts` for the auto-draft plugin on the dashboard.

        So in case that ins’t clear enough, delete just the data – not the actually structure of the tables. If you did modify the table layout, your fastest option will just be to nuke the install and redo it.

        #2 – array_walk_recursive() is a function from PHP 5. My guess would be your running PHP 4? Check what version.

        #3 – I’m fairly confident you’ll be fine on anything 1.5.X, probably back farther. The database layout in Serendipity hasn’t change much in the last few versions (that I’ve seen).

        -Jon

        • Thanks for the response :)

          1. No, you did just fine – my error was due to a lack of knowledge. Pretty much, I just didn’t know what I was doing ;). That’s how we learn, though, and I’ve figured out how to empty the tables (sans the one you suggest I don’t).

          2. I’ve had issues getting WordPress to install on PHP 5, before, so I had it on 4.1 before. I just did a fresh WordPress install using PHP 5, though my Serendipity DB is on PHP 4.1. I still receive the error, so in the serendipity.php file I commented out rows 418-420 to erase the if statement that function was attached to – and it all worked like a charm!

          Thank you very much! I never quite imagined I’d be leaving Serendipity (as much as I’d enjoyed working with, and recommended, WordPress for others), but this is going to be a good thing :)

          • #1 – Awesome!

            #2 – Ok, that would explain why the error was there. The lines around that array_walk_recursive() are for S9y Tags, so if you didn’t have any tags (S9y supported tags?!) – you wont have lost anything.

            Glad to hear it all worked out. I look forward to see how your migration work out!

  2. Maybe I am a total noob, but where do I put my old S9Y sql backup file? I have my new db setup for WordPress. I backed my old S9Y db about a year ago and now want to import it. So I guess I don’t know where to begin. :( Thanks for any help or guidance you can provide!

    • You’ll need to restore the backup file into MySQL. Once it is life in MySQL, you can use the wordpress import tool to point at that database you just restored.

      • Thanks for your help on Twitter! I’ve loaded the S9Y DB into it’s own database via Bigdump. It’s on the same server but in a different DB so as not to mix WP and S9Y. (should I have imported the S9Y SQL backup into the same DB as WordPress?) All fields are filled in properly and unfortunately nothing happens. Just says 0 items imported on every page. :( I don’t know what else to do. I feel like I am so close, and yet so far. Pic — > http://twitpic.com/2d9w1j

        • Not the same DB. Different DB’s for S9y and WP is correct. I’m curious is to how you are getting zero.

          Go into PHPmyAdmin or similar, get a SQL window open & run the following:

          use $DATABASE$;
          SELECT categoryid, category_name FROM $PREFIX$_category

          Replace $DATABASE$ and $PREFIX$ with the values you used from the import step (“Serendipity Database Name” and “Serendipity Table prefix (if any):” respectively).

          If you get no results, then you’ve got the wrong information. If you do get data out, then… we’ve got other problems.

          • That worked…..!!! (was missing the Prefix Table, sorry) to a point…Imported categories, then on the second page (importing users) I was hit with the following error:

            Catchable fatal error: Object of class WP_Error could not be converted to string in /home/perfectcr/mysite.com/wp-includes/formatting.php on line 2772

            Sorry to be a pest, I am sure you are ready to kill me. I’ll give you a huge shout out on my new site once this is all sorted I promise. Thank you again!

            • I got the exact same error (save one line):

              Catchable fatal error: Object of class WP_Error could not be converted to string in /home/html/mysite.se/public_html/wp-includes/formatting.php on line 2773

  3. FYI I replaced “mysite.com” above instead of putting my actual domain there. Wanted to say that in case there was any confusion. Thx!

  4. Figured it out!!! Apparently, you cannot have the same user name on WP as you did in S9Y nor the same email. I setup a new user in WP, logged in, and deleted the other user and the import completed! Yahoo!!

    • Sorry to spam your blog :( “One more thing”…

      I was able to run most of the SQL commands without issue, expect the below two SQL queries from your readme returned this error: #1062 – Duplicate entry ‘0’ for key ‘PRIMARY’

      UPDATE `wp_comments` as a SET a.`comment_post_ID`= (SELECT b.`menu_order` FROM `wp_posts` as b WHERE a.`comment_post_ID`= b.`ID`);

      UPDATE `wp_posts` SET `ID`=`menu_order`, `guid`=CONCAT(“http://MYURL.COM/?p=”,`menu_order`), `menu_order`=null;

      Once I get this all figured out I am going to delete the WP install and start over and do it right! :)

      • @PerfectCr did you ever figure out why you were getting an error message on this:

        UPDATE `wp_posts` SET `ID`=`menu_order`, `guid`=CONCAT(“http://MYURL.COM/?p=”,`menu_order`), `menu_order`=null;

        I am having the same problem and am wondering if this is related to an issue I’m having with comments. All of the comments have them have been transferred to the WP database, each post shows the proper number of comments, but when you click on the post no comments appear.

        ~Steve

        • That specific line updates the post ID’s to the “old” ID numbers. If that failed (but the comment line before didn’t), then your comments have been moved over to the old numbers and your post haven’t.

          Try running this:
          SELECT count(distinct(id)),count(id),count(distinct(menu_order)),count(menu_order) FROM `wp_posts` WHERE 1;

          It should return 4 numbers, all of them should be the same.

          If I’m reading it right “Duplicate entry ’0′ for key ‘PRIMARY’” means that one or more of the posts have their “menu_order” column – that which I use for the old post numbers – set to zero. If you’ve tried to run the line you pasted more than once – that is expected because it sets that field to NULL (or 0 in this case).

          • So basically, it’s not a big deal? I ignored it and started working on my site and everything appears fine. The only thing that big translate well were Tags, which I dont really care about anyway. :) THANK YOU again!

            • Well that line is important, but if your post id’s are the same… then it probably failed out on a single record (which probably isn’t a big loss).

              Pull up one of your old posts. the S9y URL will be something like /archives/123-post-name-here.html

              Now goto WP /?p=123 — If the post is the same before and after – you’re good to go (I find generally the most recent posts are the most likely to be “out of sync”). Also check if your comments on one of the S9y posts show up on the right WP post. If so… they you’re good to go.

              • Ok, I’ll dig through again and see what I can find. At first glance everything looked like it came over normal. :)

              • Hi. What’s the solution if the count is off and they’re not the same? Should I scrap the database and start over again? Thanks.

    • awesome! your comment helped me after nearly 2 hours of fiddling around with several solutions. thanks!

  5. I imported categories, users fine but posts gave me the Fatal Error: Call to a member function _real_escape() /path/to/html/wp-includes/wp-db.php on line 849

    I’m running the latest WordPress. Could that be the problem?

    Thanks,
    Robin

  6. Hi. I’m horrible at this, but I got to the point in your instructions where you say to put the file serendipity.php in the folder “import”. That folder does not exist. Am I supposed to create it? I did create one and dropped the file in there but when I log into WP’s admin area, it just shows some of the php code and not a link for me to click on. Can you please tell me what I have done wrong? Thanks.

  7. cruiser607
    2010-10-14 - 04:56

    Worked fine for me! Thank you!

  8. One Eye Pied
    2010-10-26 - 15:10

    I tried it on a local installation and it worked fine.
    Is there a way to also import the media from serendipity ?

    • I just moved the old media (/uploads/) directory from S9y to the WordPress install (/wp-content/uploads) and added a URL rewrite rule.

      #Copied S9y’s /uploads/ dir contents to /wp-content/uploads/ for this one
      RewriteRule ^uploads/(.*)$ /wp-content/uploads/$1 [R=301,L]

      (Per http://snowulf.com/2010/06/14/serendipity-to-wordpress-rewriting-urls/ )

      I never bothered to update all the old posts with new img url’s, but they still work because of this rewrite.

  9. After having renamed my WordPress user to fooDoo, and re-truncating all tables mentioned in readme.txt, I managed to get it work, apart from the last part (comments), where I got this error:

    Warning: array_merge(): Argument #1 is not an array in /home/html/mysite.se/public_html/wp-includes/comment.php on line 1370
    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 1]
    UPDATE `wp_comments` SET `comment_content` = ”, `comment_author` = ”, `comment_author_email` = ”, `comment_approved` = ‘1’, `comment_author_url` = ”, `comment_date_gmt` = ‘2011-02-15 22:59:36′ WHERE

    Done! 223 comments imported.

  10. Hi,

    the following rules:
    # Copy included serendipity.php to /wordpress/wp-admin/import/
    # Login to WordPress Admin Interface
    # Goto Tools > Import

    I cannot do? I use wp 3.21 but don’t see the serendipity import under the Import

    do you have a solution?

    • Odd. It is showing up for me. Try running ” ls /wordpress/wp-admin/import/ ” and making sure the file is in there. Also try ” chmod 755 /wordpress/wp-admin/import/serendipity.php “. Lastly you could have an issue with cacheing? Try restarting your webserver, if you have control of that.

  11. Hey! I am soon to give a move from serendipity to WP a try. I have 9000 articles and a dedicated server and am about a C+ in all this.Maybe a C-. :) I was checking to see if you were still around in case I get in trouble.
    I think my first question is how best to keep Serendipity up while I work on moving it and setting up WP? Thanks Rack.

  12. Checking to see if this issue is still alive.
    I intend to make the move this week sometime.
    My first question is should I install WP 2.X or does it work with 3.3.1

    My blog has 8000 articles.
    I have a Godaddy dedicated server with newest PHP. SCP and Putty root
    I printed the readme.
    The section of DB commands overwhelms me.
    I am sure I will have to get back to yall on that. :)

    Thanx, Rack

  13. I have serendipity installed in the root.
    I would assume I install WP into /wp to work on while serendipity runs, and then worry about changing it over later?
    Thanx
    Rack

    • Yes, if you’re limited to one domain (And no subs). Using /wp/ is probably the best. You’ll probably have a wp setting or two to fix afterwards, but thats easy enough.

  14. Before I try this 2 questions please…
    Do I need to install a 2x WP version to get this to work?
    Does NESTED categories mean SUB categories or something else?
    Thanx!
    rack

    • nope, only one copy of wordpress. Nested categories mean categories under categories. Like on the left side of my blog you see that Arduino is a subcategory of Hardware is a subcategory of tech.

  15. So Simones upgrade will take care of sub categories. Looking at the serendipity.php file I downloaded it says version 1.5. It also says tested on Serendipity 1.5.x to WP version 2.9.2.
    My Serendipity is 1.5.1 and the WP I downloaded is 3.3.1. Shall I proceed? :)

    Thanx again…

    • Should be OK. I dont think much has changed in S9y in the last few years and the WP side should be ok as long as it doesn’t complain right off the bat

      • The last entries before I came by from October showed Bas having a problem with no wp-admin/import/ directory available. After installing wp 3.3.1 I have the same issue.

        I also read in another forum, I think it was Simone, that one has to use wp 2.9 or earlier or the /import/ directory does not show up. Then upgrade later.

        When I access tools/import from admin there is a list of possibilities, serendipity not among them.

        Not sure what to do…

        Thanx…

  16. okay Thanx… Its a scary thing! :)

  17. The last entries before I came by from October showed Bas having a problem with no wp-admin/import/ directory available. After installing wp 3.3.1 I have the same issue.

    I also read in another forum, I think it was Simone, that one has to use wp 2.9 or earlier or the /import/ directory does not show up. Then upgrade later.

    When I access tools/import from admin there is a list of possibilities, serendipity not among them.

    Not sure what to do…

    Thanx…

    • rack – I just went back through your comments and removed your URL, as you keep putting in “kick” which is obviously not a valid site. You might want to enter the correct URL for your next comment. Additionally, try using “Reply to this comment” so that your messages are all part of the same thread.

  18. Sorry, kick is the NAME of the site, not the URL.

  19. How to get the serendipity.php file into WP IMPORT option?

    Using WP 3.3.1 there is no IMPORT directory to put the serendipity.php file into as directed.
    In WP ADMIN for 3.3.1 clicking on IMPORTS gives a list of about a dozen options.
    Serendipity not being one of them.

    Is there any way of getting serendipity.php into that list?
    As there is no import directory in 3.x and higher I am told.

    • I’ll have to look, they may have changed the method in which imports are done.

      • Thanx! I am at a standstill until i find an answer.

      • Well I am doing it in 2.9 now.
        I have 8500 articles which went well, I have 7500 comments but when I clicked to import comments I got this

        Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 42 bytes) in /home/kick/public_html/kick/wp-includes/wp-db.php on line 958

        not sure what to do?

        • Ok. That means you ran out or memory (duh) while importing. Check out http://drupal.org/node/207036 specifically the first php.ini section and the .htaccess section. If you can get one of the two of those to work, you’re golden. I’d suggest going for something like 64M or maybe even 128M.

          • Thanx! Finding no php.ini file I added the string to .htaccess.
            Do I turncate the DB again, or just run it and it will know only to do the comments?
            Thanks again, rack.

            • Yea, you’ll need to truncate. Unfortunately the imports don’t have a “resume”.

          • That list of UPDATE commands in the readme file has me stumped.
            I assume I do that in phpadmin under structure? But I don’t know how to do it.
            Or are those SSH commands? Maybe if you could take one of them and walk me through I can figure out the rest? And as the import went smoothly with posts, users and categories, with everything seeming to work okay, are those things necessary?
            Thanx
            Rack

            • Updates can be run in PHPMyAdmin. Just goto your wordpress database and press SQL tab.

              • Sorry this is something I have never dealt with before.

                The first on on the list, WP_COMMENTS is the most complicated to me.

                29 #* UPDATE `wp_comments` as a SET a.`comment_post_ID`= (SELECT b.`menu_order` FROM `wp_posts` as b WHERE a.`comment_post_ID`= b.`ID`);

                I pick the WP_comment table then click the SQL tab on top.

                In a window that says RUN SQL QUERY I see

                SELECT * FROM `wp_comments` WHERE 1

                I see the field options on the right with a move << button. But not sure what to do.

                :(

                Am I to just PASTE everything after the UPDATE into the window and GO?
                Or just some of it?

                Thanx for bearing with me on this…

                • rack – this appears to all be way over your head, and unfortunately, Jon’s job is limiting his ability to respond in a timely fashion. At this point, my suggestion is that you try out abdussamad’s solution. If that doesn’t work, his site mentions he offers support.

  20. abdussamad
    2012-02-16 - 03:36

    I’ve updated the plugin to work with the latest version of WordPress. You can download it here:

    http://abdussamad.com/files/2012/02/s9y_importer.zip

    The update version also supports nested comments.

  21. abdussamad
    2012-02-16 - 03:36

    Oh, BTW, its now a WordPress plugin. You stick it in wp-content/plugins and activate it before you can do the import.

  22. Hi Jon,

    I got so excited when I found this…I have over 500 blog posts that I need to import to WordPress. But the link is broken to the repository, when I try this link:

    https://code.google.com/p/snowulf/source/browse/#svn/trunk/wordpress/s9y-to-wp

    I get a 403. I think this plugin is exactly what I’m looking for…I’d really appreciate any help getting to it.

    Thanks,

    Joseph

  23. Hi, Jon!
    Thanks a lot for your great work. Had to move s9y blog to WordPress, and your script helped very much. Migrated from s9y v1.7 to WP newest. Some errors while importing, but result is that all entries imported fine. Keep doing your good work!

  24. Charles Hall
    2013-08-21 - 11:17

    Any idea if this can be easily modified to transfer a Serendipity blog into a networked WordPress installation?

    Thanks.

    Charles.

  25. Unfortunately i can’t find the serendipity installer in the tools / install option. if i put it into the plugins i can activate it but nothing more. no option to actually use it. Help?

  26. Hi Jon,

    installation of the plugin worked fine but when I enter my s9y database information I get the following message:

    Warning: mysql_get_server_info() expects parameter 1 to be resource, boolean given in /home/www/web35/html/wp-includes/wp-db.php on line 1758

    Do you have any hint?

    Best regards,
    Hannes

    • Same problem here… mysql_get_server_info() expects parameter 1 to be resource, , boolean given in /home/oreneta/public_html/margaret/wp-includes/wp-db.php on line 2146

  27. I’m trying to install but no matter what version of wordpress I try latest/2.9/2.8 after putting serendipity.php into the import directory it doesn’t show up in admin>import, i’ve tried chmod to 755 etc.

Leave a Reply