Transfering content from Joomla to WordPress

Recently I had to help with a site switch from the Joomla! CMS to WordPress. There is an tool published in the Worpdress website which can be found here:

http://codex.wordpress.org/Importing_Content#Joomla

http://www.onestopjoomla.com/extensions/migrate/joomla-to-wordpress-import-wizard/

but it doesn’t work for the new versions of these CMSes. There is an error that has to do with WordPress post_category field, which being obsolete for many versions,now has been removed.

This can be easily tackled by altering the INSERT INTO query in the index.php a bit like this:

$query = "INSERT INTO ".$wptblprefix."posts (id, post_author, post_title, post_content, post_date, post_modified, post_name) VALUES ('', '$ID5', '{$import[1][$j]}', '{$import[2][$j]}', '{$import[3][$j]}', '{$import[4][$j]}', '$post_name')";

I.e. you have to remove the “,post_category” and the corresponding VALUE. This must be done in 2 points at the code, find them with a search.

You may also easily substitute the “default” author ID in WordPress with the actual author ID from Joomla! dynamically. You can do this like that:

  • alter the SELECT from Joomla! query by adding “created_by”:
/* Performing SQL query */
$query = "SELECT id, title, introtext, `fulltext`, created, modified, created_by FROM ".$joomlatblprefix."content WHERE `sectionid` = '$section'"
  • load the VALUE into the import ARRAY:
while ($row = mysql_fetch_assoc($result)) {
$import[0][$i] = mysql_escape_string($row["id"]);
$import[1][$i] = mysql_escape_string($row["title"]);
$import[2][$i] = mysql_escape_string($row["introtext"]."<br /><!--more--><br />".$row["fulltext"]);
$import[3][$i] = mysql_escape_string($row["created"]);
$import[4][$i] = mysql_escape_string($row["modified"]);
$import[5][$i] = mysql_escape_string($row["created_by"]);

$i++;

}
  • in the while loop, replace the following code:
$j = 0;
while ($j < $i) {

/*select author */

//62,63,67,69 are the author IDs in the Joomla! database table  jos_users and author1,...,author4 are the corresponding usernames in the WordPress databse

if($import[5][$j]=="62") $authorusername="author1";
if($import[5][$j]=="63") $authorusername="author2";
if($import[5][$j]=="67") $authorusername="author3";
if($import[5][$j]=="69") $authorusername="author4"; 

/* Create an acceptable WP post_name */
$post_name = sanitize_title_with_dashes($import[1][$j]);

These changes helped me transfer my content (around 300 articles) from Joomla 1.5.16 to WordPress 3

11 comments

  1. Pingback: Jesse Petersen
  2. Pingback: KimberlyEddy
  3. hi,thanks for this article, but i have a question:
    what happens to my links submitted in google?

    i have about 5000 articles in joomla! Is there any way to save the address of the links or 301 them all to the new address in WP ?

  4. I cannot get this to work – when I visit the index.php file in a browser it is blank – no options even though I am sure the config is correct. Not even getting an error – just blank! Poo!

  5. Scratch that last one – it’s something else. The script works but won’t import. I am using WP 3.0 and Joomla 1.5.17.

    The import fails just before finishing the first post:
    _______
    Joomla2WordPress Import Wizard v3 by Azeem Khan
    Second Step
    Importing 25 items
    SELECT ID from wp_users WHERE wp_users.user_login = ‘admin’

    INSERT INTO wp_posts (id, post_author, post_title, post_content, post_date, post_modified, post_name, post_category) VALUES (”, ‘1’, ’10 Years On…A New Site!’, ‘

    POST CONTENTS HERE

    ‘, ‘2008-01-26 12:01:34’, ‘2009-02-15 23:05:48′, ’10-years-on-a-new-site’, ‘7’)

    Query failed inserting into categories

  6. nice, it worked! good that i found this post

    something to note, if your joomla article contains ’ instead of ‘ in the title, the query will fail, so edit those & it should be good

    probably other symbols not part of old ascii or your keyboard will have issues too

  7. Thanassis
    , can you possibly put updated index.php for upload, I am not sure, where and how to put properly your modifications.
    THank you!

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.