• I am reskinning a blog and using WordPress this time around. The old (existing) installation is Drupal 5.18.

    I am attempting to import all of the old posts into WordPress. I’ve done a good amount of research both on the forums/codex here, as well as elsewhere.

    I am using a (now modified) version of this SQL query (renamed the databases):

    # this assumes that both wordpress and drupal are in separate databases. The wordpress database is called "wordpress" and the Drupal database is called "drupal"
    
    # based on scripts from:
    # https://www.darcynorman.net/2007/05/15/how-to-migrate-from-drupal-5-to-wordpress-2
    # https://spindrop.us/2006/05/19/migrating-from-drupal-47-to-wordpress
    # https://www.brendanloy.com/2007/02/wordpress-21-upgrade-problems.html
    
    # first, nuke previous content in wordpress database
    use wordpress;
    delete from wp_terms;
    delete from wp_term_taxonomy;
    delete from wp_term_relationships;
    delete from wp_posts;
    delete from wp_postmeta;
    delete from wp_comments;
    
    # categories
    INSERT INTO wp_terms (term_id, name, slug)
    SELECT term_data.tid, name, name
    FROM drupal.term_data
    where term_data.vid = 2;
    
    INSERT INTO wp_term_taxonomy (term_taxonomy_id, term_id, parent)
    select term_data.tid, term_data.tid, parent
    from drupal.term_data, drupal.term_hierarchy
    where (term_data.tid = term_hierarchy.tid) AND (term_data.vid=2);
    
    # posts
    INSERT INTO
    wp_posts (id, post_date, post_content, post_title,
    post_excerpt, post_name, post_modified, post_author)
    SELECT DISTINCT
    n.nid, FROM_UNIXTIME(created), body, n.title,
    teaser,
    REPLACE(REPLACE(REPLACE(REPLACE(LOWER(n.title),' ', '_'),'.', '_'),',', '_'),'+', '_'),
    FROM_UNIXTIME(changed),n.uid
    FROM drupal.node n, drupal.node_revisions r
    WHERE n.vid = r.vid;
    
    # category --> post relationships
    INSERT INTO wp_term_relationships (object_id,term_taxonomy_id) SELECT nid,tid FROM drupal.term_node ;
    update wp_term_taxonomy set taxonomy='category';
    
    # category count updating
    UPDATE <code>wp_term_taxonomy</code> SET <code>count</code> = (SELECT COUNT(<code>object_id</code>)
    FROM <code>wp_term_relationships</code>
    WHERE <code>wp_term_taxonomy</code>.<code>term_id</code> = <code>wp_term_relationships</code>.<code>term_taxonomy_id</code>);
    
    # comments
    INSERT INTO
    wp_comments
    (comment_post_ID, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url)
    SELECT
    nid, FROM_UNIXTIME(timestamp),
    comment, thread, name, mail, homepage
    FROM drupal.comments;
    
    # users
    INSERT INTO wp_users
    (ID, user_login, user_pass, user_nicename, user_email, user_registered, display_name)
    SELECT uid, name, pass, name, mail, FROM_UNIXTIME(created), name
    FROM drupal.users WHERE uid>1;
    
    # update comments count on wp_posts table
    UPDATE <code>wp_posts</code> SET <code>comment_count</code> = (SELECT COUNT(<code>comment_post_id</code>) FROM <code>wp_comments</code> WHERE <code>wp_posts</code>.<code>id</code> = <code>wp_comments</code>.<code>comment_post_id</code>);
    
    # fix post slugs. first we have to remove the duplicate _____ chars, then replace that with a single - char
    UPDATE wp_posts set post_name = REPLACE(post_name, '__', '_');
    UPDATE wp_posts set post_name = REPLACE(post_name, '__', '_');
    UPDATE wp_posts set post_name = REPLACE(post_name, '__', '_');
    UPDATE wp_posts set post_name = REPLACE(post_name, '__', '_');
    UPDATE wp_posts set post_name = REPLACE(post_name, '_', '-');

    This imported everything except for the categories… All of the categories I had in Drupal are missing from the newly imported posts in WP.

    Does anyone know of any changes I could make to the query to get it to import everything cleanly? Or, if not, if there is some easier/more efficient way of doing this?

    Any help/advice would be much appreciated. Thanks in advance for your help!

  • The topic ‘Importing Posts From Drupal (v5.18)’ is closed to new replies.