Back to Top

How to import user from CSV in WordPress?

To import user from csv in wordpress

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.

// To load wordpress functions, load wp-load,php
$base_dir = dirname((__FILE__));

// 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]);
                $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]
    echo $insert.' users updated.';

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

Where are the LOG of PHP,MySQL and Apache

Posted on 7 years ago


Introduction to Yarn Package Manager

Posted on 1 year ago


Blank Screen of WordPress Admin Panel

Posted on 7 years ago


Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 5 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 6 years ago