WordPress

This script imports your entries from Textpattern into WordPress. It should be relatively painless, and we hope you're happy with the result.

To run this, you first need to edit this file (import-textpattern.php) and enter your Textpattern database connection details. Let's check if the database connection information works...

Everything seems dandy so far, let's get started!

It looks like your database information is incorrect. Please re-edit this file and double-check all the settings.

Step 1

First let's get posts and comments.

get_var("SELECT ID FROM $tableusers WHERE user_level = 10 LIMIT 1"); //$category = $wpdb->get_var("SELECT cat_ID FROM $tablecategories LIMIT 1"); $posts = mysql_query('SELECT * FROM textpattern', $connection); while ($post = mysql_fetch_array($posts)) { // ID, AuthorID, LastMod, LastModID, Posted, Title, Body, Body_html, Abstract, Category1, Category2, Annotate, AnnotateInvite, Status, Listing1, Listing2, Section $posted = $post['Posted']; $content = $post['Body']; $title = $post['Title']; $post_name = sanitize_title($title); $id = $post['ID']; unset($post_categories); if(!empty($post['Category1'])) $post_categories[] = $post['Category1']; if(!empty($post['Category2'])) $post_categories[] = $post['Category2']; $wpdb->query("INSERT INTO $tableposts (ID, post_author, post_date, post_content, post_title, post_name, post_status) VALUES ('$id', '$author', '$posted', '$content', '$title', '$post_name', 'publish')"); if (0 != count($post_categories)) { foreach ($post_categories as $post_category) { // See if the category exists yet $cat_id = $wpdb->get_var("SELECT cat_ID from $tablecategories WHERE cat_name = '$post_category'"); if (!$cat_id && '' != trim($post_category)) { $cat_nicename = sanitize_title($post_category); $wpdb->query("INSERT INTO $tablecategories (cat_name, category_nicename) VALUES ('$post_category', '$cat_nicename')"); $cat_id = $wpdb->get_var("SELECT cat_ID from $tablecategories WHERE cat_name = '$post_category'"); } if ('' == trim($post_category)) $cat_id = 1; // Double check it's not there already $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $id AND category_id = $cat_id"); if (!$exists) { $wpdb->query(" INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($id, $cat_id) "); } } // end category loop } else { $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $id AND category_id = 1"); if (!$exists) $wpdb->query("INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($id, 1) "); } $comments = mysql_query("SELECT * FROM txp_discuss WHERE parentid = $id"); if ($comments) { while($comment = mysql_fetch_object($comments)) { // discussid, parentid, name, email, web, ip, posted, message // For some reason here "posted" is a real MySQL date, so we don't have to do anything about it // comment_post_ID comment_author comment_author_email comment_author_url comment_author_IP comment_date comment_content comment_karma $wpdb->query("INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content) VALUES ($id, '$comment->name', '$comment->email', '$comment->web', '$comment->ip', '$comment->posted', '$comment->message')"); } } } $links = mysql_query('SELECT * FROM txp_link', $connection); while ($link = mysql_fetch_object($links)) { //id date category url linkname linksort description // See if the category exists yet $linkcat_id = $wpdb->get_var("SELECT cat_id from $tablelinkcategories WHERE cat_name = '$link->category'"); if (!$linkcat_id && '' != trim($link->category)) { $wpdb->query("INSERT INTO $tablelinkcategories (cat_name) VALUES ('$link->category')"); $linkcat_id = $wpdb->get_var("SELECT cat_ID from $tablelinkcategories WHERE cat_name = '$link->category'"); } if ('' == trim($link->category)) $linkcat_id = 1; $wpdb->query("INSERT INTO $tablelinks (link_url, link_name, link_category, link_description, link_updated) VALUES ('$link->url', '$link->linkname', $linkcat_id, '$link->description', '$link->date')"); } upgrade_all(); ?>

All done. Wasn’t that fun? Have fun.