Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7520175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:01:18+00:00 2026-05-30T02:01:18+00:00

I am trying to modify a script that was developed to import article records

  • 0

I am trying to modify a script that was developed to import article records from a Joomla (1.5.x) database into a WordPress 3.2.1 table for posts. It is a script that migrates content from Joomla to WordPress.

The issue I had with the script is that it did not maintain the unique identifier (‘id’ in Joomla, and ‘ID’ in WordPress). Based on my understanding, this makes it a lot more complicated (much more work) to deal with redirecting all the Joomla permalinks over to the new (and obviously different) WordPress permalinks. If the ID was the same in WP as it was in Joomla then some basic rewrite rules in htaccess would be enough to perform the redirections.

So I want to see if I can modify the code to force the ID rather than it being generated in consecutive order as records are inserted into the table.

The script I am modifying is available here: http://wordpress.org/extend/plugins/joomla-to-wordpress-migrator/
The file in question is called: joomla2wp-mig.php

The array is being created at around line 1049 and 1081.
At line 1049 it is:

 $wp_posts[] = array(
        'ID' => $R->id,  //I ADDED THIS IN
        'post_author' => $user_id,
        'post_category' => array($wp_cat_id),
        'post_content' => $post_content, 
        'post_date' => $R->created,
        'post_date_gmt' => $R->created,
        'post_modified' => $R->modified,
        'post_modified_gmt' => $R->modified,
        'post_title' => $R->title,
        'post_status' => 'publish',
        'comment_status' => 'open',
        'ping_status' => 'open',
        'post_name' => $R->alias,
        'tags_input' => $R->metakey, 
        'post_type' => 'post'
      );

And at line 1081 it is:

 $array = array(
 "ID"        => $item['ID'],    //I ADDED THIS IN
 "post_author"       => $user_id,
 "post_parent"       => intval($wp_cat_id),
 "post_content"      => $item['post_content'],
 "post_date"         => $item['post_date'],
 "post_date_gmt"     => $item['post_date_gmt'],
 "post_modified"     => $item['post_modified'],
 "post_modified_gmt" => $item['post_modified_gmt'],
 "post_title"        => $item['post_title'],
 "post_status"       => $item['post_status'],
 "comment_status"    => $item['comment_status'],
 "ping_status"       => $item['ping_status'],
 "post_name"         => $item['post_name'],
 "post_type"         => $item['post_type']
      );

I have commented the ID line which I have added into the top of each of these bits of array code.

The INSERT command is being implimented around line 1097

The INSERT command is put together like this:

$insert_sql = "INSERT INTO " . $j2wp_wp_tb_prefix . "posts" . " set ";

$inserted = 0;
foreach ($array as $k => $v) 
{
  if($k AND $v) 
  {
    if($inserted > 0) 
      $insert_sql .= ",";
    $insert_sql .= " ".$k." = '".mysql_escape_string(str_replace("`","",$v))."'";
    ++$inserted;
  }
}    
$sql_query[] = $insert_sql;

}

It uses the MYSQL function INSERT INTO… SET (as opposed to INSERT INTO… VALUE)

The challenge I have is this:
The array did not include the ID, so I have added this in.

Having made this change, when I run the script it will appear (at the WordPress UI end) to run fine, but no records are inserted, even though it says it was successful.

I found I could get around that issue by setting up a fresh wp_posts table with X number of blank records. Let’s say I am importing 100 articles, then I would put 100 records into the table, and they would have ID 1 to 100. When I run my modified code it will happily update and populate these existing records. What I don’t understand is why it will not create new records when I force the unique identifier (ID) to what I want it as.

I am wondering if I need to use the INSERT INTO… VALUE command instead of INSERT INTO… SET

I was going to test that out, but to be honest I am not a programmer and am just winging it as I go along. So I had not idea how to rewrite the PHP in order to impliment the structure required for the VALUE command in place of SET.

Any help or suggestions would be greatly appreciate.

I gather I have to rewrite the last bit of code I provded above.

There is some discussion on this matter at the wordpress support forums. One user (spiff06) very kindly helped troubleshoot the issue with me. We came unstuck around getting the code to insert new records with a forced identifier, and I went with what we referred to as the “messy” option (which is the method I mentioned above… setting up a table with the required number of blank records).

Even though I’ve used that “messy” method for my own site, it is my wish to make this process work cleanly for other users who are on Joomla 1.5.x and are switching to WP instead of upgrading to a newer Joomla release (which is a big process, so many are just jumping ot WP, like me).

With much thanks…

Jonathan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:01:19+00:00Added an answer on May 30, 2026 at 2:01 am

    I never found a truly automated / scripted way of doing this. I ended up doing a workaround:

    For now I’ve imported all my posts the “messy” way, by prepopulating the table.

    THE WORKSROUND METHOD
    Prepopulate the wp_posts table in the WP database with as many records as you require (look in Joomla to see how many records you have). I had 398, so I added 398 records to wp_posts.

    HOW? I did it by exporting the emtpy wp_posts table to a .csv file. I then opened this in Excel (Numbers, or OpenOffice would also do). In the spreadsheet application it was easy to autofill 1 to 398 in the ID column.

    I then reimported that .csv file into wp_posts. This gave me a wp_posts with 398 record rows with 1 to 398 in the ID field.

    I then ran version 1.5.4 of Mambo/Joomla to WordPress migrator, which can be installed from within WordPress.

    End result?

    All posts have the same ID as the original Joomla articles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to modify a script that stores my session data in a database
I'm trying to modify my GreaseMonkey script from firing on window.onload to window.DOMContentLoaded, but
I'm trying to modify the code from this script . Basically I'm trying to
I am trying to modify a batch script that installs a simple script file
I have a shopping cart script that I am trying to modify to support
I am trying to write a Python script that will access and modify the
I've got a script that I'm trying to modify so that I don't load
I'm trying to modify a ksh script to print out the line that contains
I'm trying to make a script in photoshop that will modify some layers and
I'm trying to modify the CakePHP bake script so that I can incorporate saving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.