0

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.

1 Answer 1

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

1
  • Thanks, but what about other meta values? phone number1, phone number2, DOB, address... ect.. any instruction or sample source for usermeta or post-meta?
    – pulla
    Oct 16, 2013 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.