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

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.
Hi,
I am completely new to WP and just do not find where in admin panel is the “import” function….
thanks
Pascal
What version of WordPress are you using?
1.5.2 the latest stable one…
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
Oh, ok… is it a version for previous release? does the one included in 1.5.2 works well?
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.
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?
yeah, MySQL version difference. Delete those two ADDDATE lines at the end of that query.
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”
Can you post that line between code tags here so I can see whats up?
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”
give-me your tags…
standard HTML code tags, man. And I need the code, not the error.
???? the code is just the one included in WP 2.0 RC1…supposed to be your code!?
Just to mention that I tried an import from Txp 4.0.1 … if it helps…
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.
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);
And that is still erroring?
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.
Why don’t you grab the newly modified code from the “WordPress source”:http://trac.wordpress.org/file/trunk/wp-admin/import/textpattern.php
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.
Though it was the same… will try it!
No, it’s constantly being modified because it is a _new_ script. ;)
What do you mean by “Make sure the last field before the WHERE has no comment next to it.” ?
I mean, make sure your SQL is correct.
In you last code, there is a comma after comments_count :
comments_count,
FROM ‘.$prefix.’textpattern
‘, ARRAY_A);
where is the truth?
seems here comes the issue, will try without the comma
Yes no more the same error…will examine the result precisely!! happy to find a bug in your code ;-)
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.
I presume it is normal to have lost all photos I had in my Txp post…
No preservation of images was made. However, if you used Textile to render your images, download the Textile for WordPress plugin
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
Odd. Thanks for the note. I have reopened my bug report ticket and will work out the issue this evening. Thanks!!
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…
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.
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!!
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.
And don’t convert your Textile. Use the Textile for WP plugin.
http://www.huddledmasses.org/2004/04/19/wordpress-plugin-textile-20/
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…
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.
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…
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.
You don’t have to submit a bug report but if you do more eyes will be on the problem.
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.
No, but we can always do customization work for you if you need it.
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!
What version of WP? What version of Textpattern?
I’m running Textpattern 4.0.3 and just installed WordPress 2.0.1.
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.
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.
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_?
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!
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.
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!
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 “?”?
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)
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…
…Which is to say- after importing the tables into the WP db, and pointing the script to that, it worked like a charm.
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.
I moved wordpress to the textpattern database and the import went smoothly. Thanks!
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?