admin管理员组

文章数量:1122832

I am having hard time for importing to user-meta and post-meta from my non-wp-tables. I am trying to do db migration from user table and post table to WordPress tables.

So it might be

  • user table to wp-users and wp-usermeta
  • post table to wp-posts and wp-postmeta

I have been trying to find good plugins but it's all limited. (only basic information)

My old user table has all of users information on only 1 row (1 line) such as phone number, mobile, DOB.. etc. These have to be on user-meta table.

Old user tables and wp-users are on same database now.

How can I insert user information from old user table to wp-user(for basic information) and wp-usermeta (for extra information)?

Is it possible to make it with PHP coding? (because it's on same database) I am trying to figure it out how to do with php coding or something else.

If anyone knows can you advise me a sample coding? or anybody knows any good plugins? all of them I found are not enough to put all of user information.

I am having hard time for importing to user-meta and post-meta from my non-wp-tables. I am trying to do db migration from user table and post table to WordPress tables.

So it might be

  • user table to wp-users and wp-usermeta
  • post table to wp-posts and wp-postmeta

I have been trying to find good plugins but it's all limited. (only basic information)

My old user table has all of users information on only 1 row (1 line) such as phone number, mobile, DOB.. etc. These have to be on user-meta table.

Old user tables and wp-users are on same database now.

How can I insert user information from old user table to wp-user(for basic information) and wp-usermeta (for extra information)?

Is it possible to make it with PHP coding? (because it's on same database) I am trying to figure it out how to do with php coding or something else.

If anyone knows can you advise me a sample coding? or anybody knows any good plugins? all of them I found are not enough to put all of user information.

Share Improve this question edited Oct 15, 2013 at 8:46 Eugene Manuilov 11.4k4 gold badges44 silver badges50 bronze badges asked Oct 15, 2013 at 8:30 pullapulla 7234 gold badges17 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
  1. get all data from DB1( non-wp-database ) and save to an $array.
  2. Use this wordpress code inside your functions.php for insert users into DB2 ( wordpress database).
function cxg_wp_insert_user() {
    foreach ( $array as $arr ) {
        $user_data = array(
        'ID' => '',
        'user_pass' => wp_generate_password(),
        'user_login' => $loginName,
        'user_nicename' => $nicename,
        'user_url' => '',
        'user_email' => $eMail,
        'display_name' => $displayName,
        'nickname' => '$nickname,
        'first_name' => $firstName,
        'role' => get_option('default_role')
        }
    );
    $user_id = wp_insert_user( $user_data );
}
add_action( 'admin_init', 'cxg_wp_insert_user' );
 3. After updating disable this function

NOTE : For more details about insert user goto wordpress insert user codex

本文标签: import (migration) user database to wpusers