Technosailor
  • Home
  • Blog
  • Venture Files
  • Espanol
  • Technosailor Staff
  • Twitter Pitch Me!
  • Clients/Disclosures
Nov
22
2005

Textpattern to WordPress Import Script

Posted by: Aaron Brazell

I have not been posting much the past few days because I’ve been busy at work writing a detailed Textpattern importer for WordPress. This import script, should it be included in the core source code, will allow Textpattern bloggers to make the switch to WordPress.

We even have Textile, guys! Come on in, the water is nice!

But we don’t have to wait for the code to be dropped into the source. It is a part of the official WP 2 code now. Simply

# “Download textpattern.php”:http://trac.wordpress.org/file/trunk/wp-admin/import/textpattern.php
# Edit your Textpattern database details
# Rename textpattern.php
# Upload to wp-admin/import (replace existing)
# Login to wp-admin
# Click on Import > Textpattern
# Change Log

Some details provided during the import, but that you should also know before running.

h3. Users

You have already setup WordPress, but you also have users in Textpattern. We have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. *Every _imported_ user has the same username, but their passwords are reset to password123*.

h3. Preserving Authors

Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.

h3. Textile

Also, since you’re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing “Textile for WordPress”:http://www.huddledmasses.org/2004/04/19/wordpress-plugin-textile-20/. Trust me… You’ll want it.

Enjoy.


v0.1 (Nov 23, 2005)
* Initial Release

v0.2 (Nov 25, 2005)
* Utilized WP API to insert links, cats, posts, comments and users
* Reinvented some WP API functions to assist in import
* Added link import
* Optimized code (Can anyone figure out how to make post/comment portion run in under 30 seconds???)
* General aesthetic improvements

v0.3 (Nov 28, 2005)
* Moved $txpdb to after first step to prevent importer page from crashing for non-Textpattern importers

v0.4 (Nov 29, 2005)
* Gettext improvements
* Moved TXP Database Connection settings to user submitted form
* Stored TXP database connection settings in options table
* removed global txp database connection object and replaced with per function connections
* Removed ADDDATE() function from MySQL queries to prevent MySQL version < 4.1 issues

  • Add to Mixx!
  • Stumble it!
About the Author: Aaron Brazell is the lead editor of Technosailor.com and a social media expert. His passion is to see companies and individuals use the internet and web technologies wisely and effectively to promote their brands and companies. He served as Director of Technology at b5media from 2005-2008 and is currently an independent consultant.
Tagged: import_script, php, Programming, textpattern, WordPress at 11:57 pm -

62 Responses to “Textpattern to WordPress Import Script”

  1. 1
    Pac Says:

    Hi,

    I am completely new to WP and just do not find where in admin panel is the “import” function….

    thanks
    Pascal

    November 28th, 2005 at 10:17 am
  2. 2
    Aaron Says:

    What version of WordPress are you using?

    November 28th, 2005 at 10:19 am
  3. 3
    Pac Says:

    1.5.2 the latest stable one…

    November 28th, 2005 at 10:26 am
  4. 4
    Aaron Says:

    The importer works only with 2.0 which is forthcoming. It’s in beta as we speak. “Use at your own risk”:http://wordpress.org/download/nightly-builds/wordpress-2.0-beta-1.zip

    November 28th, 2005 at 10:32 am
  5. 5
    Pac Says:

    Oh, ok… is it a version for previous release? does the one included in 1.5.2 works well?

    November 28th, 2005 at 10:35 am
  6. 6
    Aaron Says:

    There is no version for previous release and I don’t have any intention of releasing one. 1.5.x will soon not be the standard.

    November 28th, 2005 at 7:14 pm
  7. 7
    Pac Says:

    Ok I have installed the WP 2.0 RC1 and use the embedded script to import from Txp… I have the following error when I try to import posts :
    WordPress database error: [You have an error in your SQL syntax near '"INTERVAL 1 HOURS") AS post_date_gmt, ADDDATE(LastMod, "INTERVAL 1 HOU' at line 15]
    SELECT ID, Posted, AuthorID, LastMod, Title, Body, Excerpt, Category1, Category2, Status, Keywords, url_title, comments_count, ADDDATE(Posted, “INTERVAL 1 HOURS”) AS post_date_gmt, ADDDATE(LastMod, “INTERVAL 1 HOURS”) AS post_modified_gmt FROM txp_textpattern

    any idea?

    November 29th, 2005 at 3:49 am
  8. 8
    Aaron Says:

    yeah, MySQL version difference. Delete those two ADDDATE lines at the end of that query.

    November 29th, 2005 at 6:19 am
  9. 9
    Pac Says:

    mmm, now have this error again for posts import :
    “WordPress database error: [You have an error in your SQL syntax near 'FROM txp_textpattern ' at line 15]
    SELECT ID, Posted, AuthorID, LastMod, Title, Body, Excerpt, Category1, Category2, Status, Keywords, url_title, comments_count, FROM txp_textpattern”

    November 29th, 2005 at 7:35 am
  10. 10
    Aaron Says:

    Can you post that line between code tags here so I can see whats up?

    November 29th, 2005 at 7:46 am
  11. 11
    Pac Says:

    mmm, now have this error again for posts import :
    WordPress database error: [You have an error in your SQL syntax near 'FROM txp_textpattern ' at line 15]
    SELECT ID, Posted, AuthorID, LastMod, Title, Body, Excerpt, Category1, Category2, Status, Keywords, url_title, comments_count, FROM txp_textpattern”

    November 29th, 2005 at 7:55 am
  12. 12
    Pac Says:
    Z>֭iy뢶(yޮ+|.̧gyD-ƛ^Z׫ewHB	2>-y.+ 2ڲ(u8hw!1q&z
    +P(-nŠݲ+ey&.Q8qױ
    November 29th, 2005 at 7:55 am
  13. 13
    Pac Says:

    give-me your tags…

    November 29th, 2005 at 7:56 am
  14. 14
    Aaron Says:

    standard HTML code tags, man. And I need the code, not the error.

    November 29th, 2005 at 8:03 am
  15. 15
    Pac Says:

    ???? the code is just the one included in WP 2.0 RC1…supposed to be your code!?

    November 29th, 2005 at 9:02 am
  16. 16
    Pac Says:

    Just to mention that I tried an import from Txp 4.0.1 … if it helps…

    November 29th, 2005 at 1:22 pm
  17. 17
    Aaron Says:

    It is my code and I told you to remove the two ADDDATE lines from the code, then you reported you were still getting an error.

    So IF you followed my instructions and by doing so you still are getting an error, then I want to see the modified code.

    November 29th, 2005 at 2:13 pm
  18. 18
    Pac Says:

    Ok, now it is clear to me… Here is the code where I remove the 2 lines:
    return $txpdb->get_results(’SELECT
    ID,
    Posted,
    AuthorID,
    LastMod,
    Title,
    Body,
    Excerpt,
    Category1,
    Category2,
    Status,
    Keywords,
    url_title,
    comments_count,
    FROM ‘.$prefix.’textpattern
    ‘, ARRAY_A);

    November 29th, 2005 at 2:24 pm
  19. 19
    Aaron Says:

    And that is still erroring?

    November 29th, 2005 at 2:26 pm
  20. 20
    Pac Says:

    yes! here it is :

    WordPress database error: [You have an error in your SQL syntax near 'FROM txp_textpattern ' at line 15]
    SELECT ID, Posted, AuthorID, LastMod, Title, Body, Excerpt, Category1, Category2, Status, Keywords, url_title, comments_count, FROM txp_textpattern

    Done! 0 posts imported.

    November 29th, 2005 at 2:45 pm
  21. 21
    Aaron Says:

    Why don’t you grab the newly modified code from the “WordPress source”:http://trac.wordpress.org/file/trunk/wp-admin/import/textpattern.php

    November 29th, 2005 at 3:12 pm
  22. 22
    Aaron Says:

    Just to let you know, I’ll be making additional changes to the script tonight including the removal of ADDDATE functions. Download the newest cose above and remove those ADDDATE lines again. Make sure the last field before the WHERE has *no* comment next to it.

    November 29th, 2005 at 3:14 pm
  23. 23
    Pac Says:

    Though it was the same… will try it!

    November 29th, 2005 at 3:15 pm
  24. 24
    Aaron Says:

    No, it’s constantly being modified because it is a _new_ script. ;)

    November 29th, 2005 at 3:16 pm
  25. 25
    Pac Says:

    What do you mean by “Make sure the last field before the WHERE has no comment next to it.” ?

    November 29th, 2005 at 3:21 pm
  26. 26
    Aaron Says:

    I mean, make sure your SQL is correct.

    // Get Posts
    return $txpdb->get_results('SELECT 
                                                                         ID,
    Posted,
    AuthorID,
    LastMod,
    Title,
    Body,
    Excerpt,
    Category1,
    Category2,
    Status,
    Keywords,
    url_title,                                                                                comments_count                                                                                                                                                        FROM '.$prefix.'textpattern                                                                        ', ARRAY_A);
    November 29th, 2005 at 3:25 pm
  27. 27
    Pac Says:

    In you last code, there is a comma after comments_count :

    comments_count,
    FROM ‘.$prefix.’textpattern
    ‘, ARRAY_A);
    where is the truth?

    November 29th, 2005 at 3:30 pm
  28. 28
    Pac Says:

    seems here comes the issue, will try without the comma

    November 29th, 2005 at 3:32 pm
  29. 29
    Pac Says:

    Yes no more the same error…will examine the result precisely!! happy to find a bug in your code ;-)

    November 29th, 2005 at 3:33 pm
  30. 30
    Aaron Says:

    at mysql.com, man. Commas separate fields. comment_counts is the last field you’re selecting in the snippet I just gave you. In the old code, comma_count was followed by two more fields ran through the ADDDATE() function.

    November 29th, 2005 at 3:33 pm
  31. 31
    Pac Says:

    I presume it is normal to have lost all photos I had in my Txp post…

    November 29th, 2005 at 3:36 pm
  32. 32
    Aaron Says:

    No preservation of images was made. However, if you used Textile to render your images, download the Textile for WordPress plugin

    November 29th, 2005 at 3:37 pm
  33. 33
    Pac Says:

    Just to let you know, in order for you to improve the script if possible that the comments where all imported but without link to the post and the post itself the sql value “comment_count” was not updated too… done the trick through phpmyadmin but not so convenient if you import alot of comments

    November 30th, 2005 at 7:38 am
  34. 34
    Aaron Says:

    Odd. Thanks for the note. I have reopened my bug report ticket and will work out the issue this evening. Thanks!!

    November 30th, 2005 at 7:49 am
  35. 35
    Chris L Says:

    I just tried this script and it worked great… but I was wondering if it would be possible to have an option to maintain the same ID for posts?

    My current URL scheme in textpattern is:
    http://site/article/post-id/url-title

    I can migrate to WP *and* maintain all the current links to my posts if I can keep the post-id the same during the transition…

    January 8th, 2006 at 12:16 am
  36. 36
    Aaron Says:

    Chris, I don’t think that will be possible. The reason is the WP API. When inserting posts, if you include an ID then WordPress assumes “edit” mode, not “insert” mode.

    January 8th, 2006 at 12:32 am
  37. 37
    Chris L Says:

    Too bad. Two other things:

    1) when I Tried the script with my txp db being different from my wp db, it failed.

    2) Is the post_name for the posts in the wpdb copied from the txp db (rather than re-created)? If so, I can probably write a script to update the new wp database with the proper post_id based on the post_name…

    Then all I have to do is write a script to convert all the textile formatting in the wpdb and I think I’m done!

    Thanks for your work on the import script!!

    January 8th, 2006 at 12:57 am
  38. 38
    Aaron Says:

    I tested it with my txp db being different…. In fact, that was how I developed it. However they do have to be on the same server unless the TXP db allows remote connections. Thats more a MySQL issue.

    post_name is a direct copy of urltitle. I should have, in hindsight, ran TXP’s $Title through sanitize_title() but I did not. Theoretically they should be the same thing but I still prefer the safety of the WP API.

    January 8th, 2006 at 1:20 am
  39. 39
    Aaron Says:

    And don’t convert your Textile. Use the Textile for WP plugin.
    http://www.huddledmasses.org/2004/04/19/wordpress-plugin-textile-20/

    January 8th, 2006 at 1:22 am
  40. 40
    Chris L Says:

    Well, the script wouldn’t work for me until I put them in the same db. It kept giving me errors because it was looking for my WP tables in the db I had specified for TXP– and it didn’t exist there. The fix was to move my WP tables to the same DB, then it worked fine. They are all on the same server.

    As for Textile– thanks for the pointer. I am aware of the plugin, but I want to stop using it for various reasons, and if I turn it off in WP, then of course all my textile posts will look horrible. Ideally a plugin would let me select which formatting engine to use when (of course, ideally WP would store posts in both original and translated form as TXP does :), but since I haven’t found a good WP 2.0 solution for that…

    January 8th, 2006 at 1:31 am
  41. 41
    Aaron Says:

    Are you using the importer included with WP 2.0? The TXP database object is its own separate connection object with the variables passed in through a form on page 1 of the importer. It actually sounds like you might have an older version of the importer.

    January 8th, 2006 at 1:32 am
  42. 42
    Chris L Says:

    Yeah, it was in the WP I just downloaded today… if I have time I will try to replicate and be more specific. But I remember very clearly that on the very first section (categories) it was failing and the queries it was showing were being run against the wrong db…

    January 8th, 2006 at 1:45 am
  43. 43
    Aaron Says:

    Yeah if you can replicate that that’s great. Also submit a bug to WP since the importer is part of the official core now.

    January 8th, 2006 at 1:47 am
  44. 44
    Aaron Says:

    You don’t have to submit a bug report but if you do more eyes will be on the problem.

    January 8th, 2006 at 1:48 am
  45. 45
    Brendan Says:

    Will this also bring over custom Textpattern fields? My current Textpattern installation has several custom fields to hold post metadata; I guess I could fill them all in again in WP, but it’d be kind of a pain.

    January 20th, 2006 at 2:43 am
  46. 46
    Aaron Says:

    No, but we can always do customization work for you if you need it.

    January 20th, 2006 at 7:43 am
  47. 47
    Robert Ellis Says:

    When I run the importer, I get these error messages:

    WordPress database error: [Table 'future_futurosity.wp_options' doesn't exist]
    SELECT option_value FROM wp_options WHERE option_name = ‘tpre’ LIMIT 1

    Importing Categories…

    WordPress database error: [Table 'future_futurosity.wp_categories' doesn't exist]
    SELECT cat_ID FROM wp_categories WHERE category_nicename = ‘textpattern’

    Etc. (it keeps going, and I get similar errors on every page—users, posts, etc.).

    Any help would be greatly appreciated!

    February 11th, 2006 at 12:14 pm
  48. 48
    Aaron Says:

    What version of WP? What version of Textpattern?

    February 11th, 2006 at 12:16 pm
  49. 49
    Robert Ellis Says:

    I’m running Textpattern 4.0.3 and just installed WordPress 2.0.1.

    February 11th, 2006 at 12:31 pm
  50. 50
    Aaron Says:

    And are you using the Textpattern importer that came with WordPress or did you download it from here?

    I’m not aware of any database changes that came between TXP 4.01 (which is what I referenced when building the importer) and 4.03, but maybe you know of some as a TXP user.

    February 11th, 2006 at 12:37 pm
  51. 51
    Robert Ellis Says:

    I tried both importers, yours and the one that came with WordPress, and I get the same error messages with both. I don’t think there were any changes to the database between 4.0.1 and 4.0.3.

    Am I supposed to import my Textpattern tables into the WP database before importing? Seems odd, but I thought I saw a comment regarding that above.

    February 11th, 2006 at 12:48 pm
  52. 52
    Aaron Says:

    It helps if they are in the same database, and it helps if they are on the same server, but no you don’t have to import them. The importer does that for you.

    I am presuming you have actually installed WordPress succesfully before attempting to import?

    I also presume your WordPress table prefix is wp_?

    February 11th, 2006 at 12:58 pm
  53. 53
    Robert Ellis Says:

    Yes, WP was successfully installed and the table prefix is wp_. I moved the Textpattern tables into the WP database (they were in separate databases on the same server) and the import seems to be working now (I have a few hundred entries so it’s taking a long time). Things seem to be okay so far. Thanks very much!

    February 11th, 2006 at 1:39 pm
  54. 54
    Aaron Says:

    Cool!

    The only thing I can think of is that the first page of the importer prompts you for your Textpattern database info and you might have thought it wanted your WP info.

    February 11th, 2006 at 1:43 pm
  55. 55
    Robert Ellis Says:

    Nope, I entered the info for the Textpattern database. It was only after moving the tables into the WP database and specifying the WP database that it worked. But I think I’ve got it now. Thanks again!

    February 11th, 2006 at 4:09 pm
  56. 56
    Andrei Maxim Says:

    Hi,

    It seems that there are some issues with UTF-8 characters, like ă, î, ş, ţ and â.

    What needs to be changed so I can see the proper characters instead of “?”?

    February 18th, 2006 at 8:27 am
  57. 57
    Jack Says:

    For the record, I also had to add my existing textpattern tables into the target wordpress database before the import worked. Specifying a separate Textpattern database failed with the same error as above. (Textpattern 4.0.2 to WP 2.0.2)

    April 1st, 2006 at 11:38 am
  58. 58
    brendon Says:

    I have another example of what Jack and Robert are reporting- my TXP install is 4.03, and I downloaded the newest Wordpress… I have the DB’s on the same server, same install of mysql, but the import shows errors like this:

    WordPress database error: [Table 'textpattern.wp_bb_1_categories' doesn't exist]
    SELECT cat_ID FROM wp_bb_1_categories WHERE category_nicename = ‘misc’

    WordPress database error: [Table 'textpattern.wp_bb_1_categories' doesn't exist]
    SELECT cat_ID FROM wp_bb_1_categories WHERE category_nicename = ‘food-dining’

    Wherein “textpattern” IS the db name I entered on the previous page for my textpattern, and wp_bb_1 is the proper table prefix for this WP install.

    Does this mean the first step of your script is to create WP-style tables in my TXP db and map over the data, THEN export it to the WP database? Or is it somehow writing to the wrong one? Or do am I completely lost and should stop while I’m behind? :)

    ANyway- I’m going to try the “import tables into WP database” method for now and see how that works…

    Thanks…

    April 20th, 2006 at 7:57 pm
  59. 59
    brendon Says:

    …Which is to say- after importing the tables into the WP db, and pointing the script to that, it worked like a charm.

    April 20th, 2006 at 8:04 pm
  60. 60
    a. Says:

    Hi! I’m hoping you can help me. I tried the import feature and get the following errors (among others…)

    When attempting to import textpattern posts to wordpress I get the following error:

    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 '/txp_category WHERE type = "article"' at line 5]
    SELECT id, name, title FROM /txp_category WHERE type = “article”
    No Categories to Import!

    Can you point me in the right direction to correct this? I don’t know anything about importing tables,etc. Any help is appreciated. Thanks.

    April 22nd, 2006 at 10:11 pm
  61. 61
    a. Says:

    I moved wordpress to the textpattern database and the import went smoothly. Thanks!

    April 23rd, 2006 at 5:07 am
  62. 62
    R Salama Says:

    Hello,

    I’ve done the import without any drama. And I’ve installed the textile for wordpress plugin, again without any drama.

    However, I use the following to produce a thumbnailed image that can be clicked to produce a full sized image in a new window:

    Now, this doesn’t work after import, and it’s a bit of showstopper. Any help?

    January 20th, 2007 at 10:51 am

Or add a Video Comment
with
« Back to text comment
  • Recent Posts

    • Are People Talking About You?
    • Western Style Writing vs. Eastern Style Writing
    • How Has Social Software Changed Your Life?
    • America the Beautiful
    • Identi.ca and the Art of the Launch
  • Reader Contribution

    • Brian Clark on Western Style Writing vs. Eastern Style Writing
    • Jeffrey on Western Style Writing vs. Eastern Style Writing
    • Jeffrey on What a designer is and isn’t…seriously you need to know…
    • Igor The Troll on Are People Talking About You?
    • Aaron Brazell on 10 Things You Need to Know About WordPress 2.6
  • RSS Venture Files

    • The Difference Between Designers and Marketers
    • But this worked four years ago?
    • Rules for Entrepreneurs - Avoid relying on a few whale customers
    • 6 Steps to Successful Small Business PR
    • Rules for Entrepreneurs - Outsource what you suck at
  • RSS Wicked Marketing

    • Yeah it’s cheaper, but what are you really getting?
    • What a designer is and isn’t…seriously you need to know…
    • The difference between success and closing next year…
    • It’s time to get Wicked…
  • RSS Technosailor en Español

    • PopTok: usa tus películas favoritas para enviar un mensaje
    • Video en Vivo desde tu iPhone
    • 7 Funciones que le Faltan al iPhone 3G
    • Como Vencer la Sobrecarga Informativa
    • La Batalla es Digital
  • Tip Jar


  • License Creative Commons Attribution-Noncommercial-Share Alike 3.0 | Copyright © 2004 - 2008 - Aaron Brazell | Lisa helped out | Privacy Policy

    Twitter Pitch!

    <p>Twitter pitching is a form of pitch that requires succint "what does this mean for me" kind of pitching. It is the ultimate efficiency of words. You have 140 characters or less to tell me why your pitch matters to me or my readers. Please include a means of contacting you. This is included in your 140 characters. If you send successive pitches, you will likely be ignored, unless it's obvious that the first pitch was a case of "accidental send", etc.</p> <p>This form of pitching does not mean I'm being a diva. It means that my time is valuable, and you want a piece of it. It's good practice for you, and delivers your pitch in a format I want. Win-win.</p>


    (X) Close

    Twitter Pitch Me!