WP CSV to Database plugin allows you to insert CSV file content into WordPress database. Useful when you want to bulk upload data from your CSV file (e.g. product details) to the WordPress database (MySQL) in one go.
If you didn’t know what a CSV file is then you can learn more from Wikipedia. You can use Microsoft Excel to enter all your data and then save the file as a CSV file.
Many of my WordPress Shopping Cart users have requested me to add an option so that they can bulk upload their product details into the database from a CSV file (really useful when you have hundreds of products). Hopefully this plugin will satisfy that need and in addition you will be able to use it to bulk upload any data into your WordPress database to save you time.
Installation of the Plugin
- Go to the Add New plugins screen in your WordPress admin area
- Click the upload tab
- Browse for the plugin file (wp-csv-to-db.zip)
- Click Install Now and then activate the plugin
Usage of the Plugin
Step 1 (Select Database Table):
- All WP database tables will be queried and listed in the dropdown box.
- Select the table name which will be used for the query.
- Once the table is selected; the “Table Preview” will display the structure of the table.
- By structure, this means all column names will be listed in the order they appear in the database.
- This can be used to match the .csv file prior to execution; and verify it contains the same structure of columns.
Step 2 (Select Input File):
- The option will be used to locate the file to be used for execution.
- A direct url to a .csv file may be entered into the text field.
- Alternatively, the “Upload” button may be used to initiate the WordPress uploader and manager.
- From here, the file can be uploaded from a computer or selected from the media library.
- The “Number of .csv file Columns” will populate when the Input File field contains a valid .csv file.
Step 3 (Select Starting Row):
- The .csv file will contain rows, which get converted to database table entries.
- This option will allow customization of the starting row of the .csv file to be used during the importation.
- Row 1 is always the top row of the .csv file.
- For example: If the .csv file contains column headers (column names), it would most likely be desirable to start with row 2 of the .csv file; preventing importation of the column names row.
Step 4 (Disable “auto_increment” Column):
- This option will only become available when a database table is selected which contains an auto-incremented column.
- If importing a file which already has an auto-incremented column… this setting most likely will not be needed.
Step 5 (Update Database Rows):
- By default, the plugin will add each .csv row as a new entry in the database.
- If the database uses a primary key (auto-increment) column, it will assign each new row with a new primary key value.
- This is typically how entries are added to a database.
- However; if a duplicate primary key is encountered, the import will stop at that exact point (and fail).
- If this option is checked, the import process will “update” this row rather than adding a new row.
Download Latest Version
Download the CSV to DB plugin.
How to Use This Plugin to Bulk Upload WP eStore Products
If the cell values in the CSV file have special characters like apostrophe (‘) or quotes (“) then don’t forget to use a backslash before them (e.g Karen\’s book). You shouldn’t need to do this anymore if you are using v1.5 or above.
The video tutorial on the following page might also be a good resource for importing data into your WordPress database table:
If you have any issues with the plugin please leave a comment below.
Check out our WordPress plugins page for more cool WordPress plugins.
Comments (76 responses)
It is not going to automatically create categories. So you will need to setup the categories in WordPress then just import the data into the database.
Does this plugin let you add new pages of content and create categories for that content? I have 1000s of pages of content that need to be added to my new WP install, but I don’t want to do it manually.
Or do I set up the categories/menus in wp-admin then use the plugin to upload the content to each specific page/category?
Thank you for the plugin. I am using it with Windows Server (PHP-CGI) and it seems that needs this before fopen to work:
and after fclose
It was my duty to explain my experience, especially against Ruhul that has provided us this useful plugin.
I’ve re-read my comment and i’m sorry for a couple of grammatical errors, i did a long comment and i’m not an experienced english speaker/writer!
Thank you for explaining the issue you where having in detail and how you fixed. =)
Really useful plugin!
Anyway i had to fight a bit to have it working, but mainly for my low knowledge and personal features required.
I write this comment also to avoid people marking the plugin as “not working” or giving a low rate, that’s a top-notch plugin for who, like me, create themes itself and customize wordpress in deep.
Here it is my experience:
I exported a CSV from Microsofts Excel, comma value, but as i don’t know so much excel, i simply exported it without checking all the options.
So i had in output a CSV file with field delimitations defined by semicolons “;”, with windows line endings, and western windows text encoding.
(Discovered then that’s a totally wrong CSV file format for the “CSV to Database” plugin)
After some times that the plugin said “Import succesfull” but in phpMyAdmin i didn’t saw any imported data, i tought about changing the Text Encoding of the CSV to “UTF-8” and the line endings to “UNIX Line Endings (LF)” as in the past i had this kind of problems with CSV files.
I re-tried the import, message was alway “Import successfull”, but, as before, in phpMyAdmin i didn’t saw any imported data.
So i did some webseraches and i found that the CSV file for the “CSV to Database” plugin must have the fields delimited by commas “,”.
Changed all the delimitations from semicolons “;” to commas “,”:
Now the plugin import successfully imported the data and i verified also in phpMyAdmin that the data was really imported to the database!!
Now the second problem:
Ok, i’ve the CSV, it’s uploaded and that’s fine. But i will sometimes update that Table with a new CSV file, maybe a CSV that have the same rows but with some fields modified, or with some rows added having the other rows unmodified.
What happen if i upload a new CSV?
It will be add the new data in the Table either if there are duplicate fields!
My “poor” solution came immediately in my mind: TRUNCATE and then INSERT!
So i’ve added these following code lines after line 36 of the plugin:
// ADDED TO CLEAN TABLE
$trunk = “TRUNCATE TABLE $table_name”;
$trunked = $wpdb->query($trunk);
// ADDED TO CLEAN TABLE
It’s important to place them before the while cycle:
“while (!feof($file_handle) )”
Otherwise you will have a loop of TRUNCATE and then INSERT resulting in an import of the last row only from the CSV file!
So be careful!
Probably my solution isn’t the best one, but if you need to clear everytime your table and then insert new data from a CSV file…well, that modify could be useful!
For a generic, free tool that allows you to load CSV files into any database, check out CSVexpress.
You gotta format the date correctly. MySQL date values are formatted like the following:
The following video tutorial should help:
This is an awesome plugin, i just have one question for you. I am using it to import posts to the wp_posts table from a csv file. Everything imports correctly except the date.
In the CSV file, the date is formatted like this:
upon import, the DB shows this:
Ok,, thank you for the assistance!
All comments should go to the “wp_comments” table (its one of the core tables of WordPress).
@admin, thanks for your reply. It shouldn’t be hard to import the comments into SQL, I have experience doing it. Do all comments plugins for wordpress make use of the same wp_comments table?
@Mike, I don’t know of any comments plugin that lets you import comments but I think all you really need is to insert the comments into the “wp_comments” table in WordPress. This article might help you to where you can do it yourself:
Hi, do you have any suggestions as to a good comments plugin for WordPress that isn’t too terribly difficult to import comments into? I have a few posts from my old Joomla site that have close to 1200 comments and they serve well for credibility purposes. I recently imported 530 reviews from CSV into the SQL table for WP Customer Reviews which was great! I just need to do the same thing for my comments. But just curious if you had any recommendation for a good comments plugin?
Ahhh…that will help enormously.
I’ll watch that video tutorial now, then delve into mycPanel MyPHPAdmin to create a table. I did manage to find some reference to the description field like you’re saying, & it said make the description field type “longtext”.
Many thanks for all that & I’ll be back…to let you know the outcome. Cheers & avagoodweekend!
Just wanted to add… this tutorial might come in handy for you:
Okay… when you are importing content into database you need to tell it where to go to (basically, it needs a table that can store that content). So if you are trying to import that data into your database you need to create a table first that can hold that data and has the column structure to do so. For the description field you can use a “text” type which will allow you to put long descriptions without limiting you.
The merchant datafeed I want to import uses the following standard Shareasale column format >>
ProductID Name MerchantID Merchant Link Thumbnail BigImage Price RetailPrice Category SubCategory Description Custom1-OnSaleDate Custom2-Genre Custom3-People Custom4-Theme Custom5-Popularity LastUpdated status manufacturer partnumber merchantCategory merchantSubcategory shortDescription ISBN UPC
where the Description field per product per row has at least a paragraph of text. The error messages seem to be associated with the amount of text (lots) in this field entry.
As well, I’m uncertain what to put in the Database Table Name in Step 1 Specify General Options when using your plugin, as I’m not importing into your eStore. Do I have to create a table within the database? Although I’ve been heavily into PC technology for decades, database stuff is relatively new to me 😉
I’d attach some screenshots to show you more clearly but there is nowhere to attach files in this comments field.
@Brent, I am not sure what you mean by the description field. The description field of which table? Which table are you trying to import this to? I can’t tell you if there is a limit if I don’t even know which database table you are referring to.
I’m trying to use this plugin using a standard csv format datafile from a merchant. To trial the import process, I created a new site http://ScienceFictionFantasy.info with a fresh install of WordPress (latest 3.2.1), installed your Importer plugin then took the merchant’s datafeed into Excel & deleted all entries except 5 so I could use a small test file. After saving it as a csv again, I then went through your 3-step process & got error messages that indicated a number of problems partway through the Description field of each Data entry.
Is there a limit to the characters it can handle in each Description field entry? I can email any further detail as required if you tell me what else you require to solve the problem, eg. the datafeed test sample (tiny) or complete file (huge, not tested yet), the error message as a screenshot jpg to look at, my WP Admin login info, what else?
BTW, I couldn’t post this on the forum as you prefer, because we haven’t bought anything yet (after we get this sorted, we’ve got a client that wants to add digital products to their WP website very soon so the eStore plugin looks imminently suitable.
Thanks in advance.
@Ed, The path to file doesn’t seem complete:
Did you upload the file using this plugin or did you upload it using the WordPress medial uploader then just used the URL? Also, are you using the version downloaded from this page or an older version of CSV to DB plugin?