I am sure that you have read my one of the previous article about how to import terms from CSV in wordpress and today I am going to explain one article which is about to import user in WordPress from CSV file.
Nowadays, WordPress is used for all kind of websites. You can develop any of your site in WordPress. So, sometimes you want to migrate your users from another platform to WordPress, here is the solution.
Here is the script which will be used to import your users into WordPress database from the csv file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | // To load wordpress functions, load wp-load,php $base_dir = dirname((__FILE__)); require_once($base_dir."/wp-load.php"); // declare global variable global $wpdb; $insert = 0; $update = 0; if(isset($_FILES['users']['name']) && $_FILES['users']['name'] != '') { if (($handle = fopen($_FILES['users']['tmp_name'], "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if($data && !empty($data)) { $user_id = username_exists($data[1]); if(($user_id==’’)){ $user_id = wp_insert_user(array( 'user_login' => $data[1], 'user_pass' => 'password', // Password of users 'user_email' => $data[4], 'role' => 'user', // role of your user 'user_nicename' => $data[3], 'display_name' => $data[9] )); $insert++; } } } fclose($handle); } echo $insert.' users updated.'; } <form method="post" enctype="multipart/form-data"> <input type="file" name="users" /> <input type="submit" value="Submit" /> </form> |
Read: Add items to top navigation in WordPress
As per above code, Create one PHP file and write code and make changes as per your field(column) into CSV and import. That’s it.
Hope this helps someone else out.As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.