Importing Posts from CSV file into WordpressMarch 28th, 2008
Problem: I have a big excel spreadsheet with posts and extra fields and I want to import it into Wordpress.
I haven’t found a plugin to do this so I decided to make my own. It’s not complete, and it’s not quite a ‘plugin’ but it works. Here’s how to do it:
- Download CSV_Import class from me. csv2 post.
- Unzip and up load the file called csv.php to /wp-admin/import/
- Prepare your csv file, here is a sample file. It’s really a pipe delimited file. It MUST follow this format or it will not work. Make sure you include the header row.

- In admin panel , go to Manage, Import, choose CSV
- The rest is pretty self explanitory, upload file, pick a user, and voilá

April 1st, 2008 at 5:05 pm
NICE. I’ve been searching for something like this for-ev-er. I’m about to use it to create 288,000 pages. I will probably break it down into bite size chunks so everything doesn’t choke and die.
Any idea how many this can handle. Oh, and can I create unlimited (16 or so) fields with this? And can it create pages also or just posts? Sweet ass work, get a donation button doood.
April 2nd, 2008 at 2:08 pm
I am having troubles… can you look at this text file and help me figure out what I’m doing wrong?
wp_title|wp_post_date|wp_category|wp_content|zip|website|phone|attorney|position|sex|employees|revenue
A Conflict Management Ctr|12/31/07 23:59|anchorage|310 K St # 200|99501-2064|Not Available|9072646687|Not Available|Not Available|Not Available|6|1002000
A Fred Miller Attorneys At Law|12/31/07 23:59|ketchikan|426 Main St|99901-6316|Not Available|9072256666|A Fred Miller|Owner|Male|5|835000
A Robert Hahn Jr|12/31/07 23:59|anchorage|1500 W 33rd Ave|99503-3639|Not Available|9072791544|A Robert Hahn Jr|Not Available|Male|2|334000
April 2nd, 2008 at 2:52 pm
Hey 7th loyal reader!
First things first, I’m glad you liked the code…even if it hasn’t worked for you yet.
I haven’t tested the code on WP 2.5 yet. The problem with your file though I think is the date format. You must follow
YYYY-MM-DD HH:MM:SS:MS
(dashes not slashes)…hope that was it.. let me know.
April 12th, 2008 at 5:13 am
thanks for this awesome plugin.
i am working on a new project and need to import about 2000 posts.
every post includes an excerpt and data for the plugin “All in One SEO Pack”.
can i import these fields as well?
i assume i have to look in the mysql table for the corresponding table name and just add it to the csv file.
April 12th, 2008 at 6:04 am
Hey Michael,
Sorry man…excerpts are not officially supported yet. I’ll work on it. Check back. Another thing, the plugin uses all WP functions…doesn’t talk directly to MySQL.
April 12th, 2008 at 11:27 am
Hey Zack,
I usually build my websites tree on spreadsheet so I will have the different levels of the website [categories(first level)--> subcategories(second level) --> sub-subcategories(third level)] deployed there.
I would like to import this into WP.
Is there a way to achieve this with your plugin?
April 12th, 2008 at 2:33 pm
Hey Nick,
I’m currently adding support for cats/subcats. Check back.
April 13th, 2008 at 12:04 pm
thanks for the update Zack,
you saved me hours of mindnumbing work.
April 14th, 2008 at 8:35 pm
Hey Zack,
Thanks for your reply. I already checked the update you posted but still can´t make it to do what I need…can I create with the updated version you posted sub-categories already?
If yes, could you provide a short example of the required syntax to define properly the child categories? Already tred but got no luck.
It would be great REALLY to have as many child categories created as desired.
Also, like mentioned above by Michael, the possibility to have titles, tags, etc passed to the All-in-One-SEO-Plugin would be Heaven.
All heavy WP users use it extensively so if you achieve this, your plugin is gonna rock for sure.
Thanks again for your time and keep it up! Looking forward for the updates.
April 15th, 2008 at 3:46 pm
Any news Zack?
April 15th, 2008 at 5:32 pm
Hey Nick, see the new post
April 16th, 2008 at 7:18 am
Hey Zack,
Nice job…worked like charm. I am not sure if I missed it but are we able with the new version to pass parameters to the All-in-One SEO plugin?
Not sure if this can be achieved via the additional field tags…
Cheers
April 16th, 2008 at 7:21 am
Actually, would be great if you could provide a quick overview of how we’re supposed to use the extra fields & excerpts columns…
April 17th, 2008 at 2:13 am
Hey Nick,
you can pass parameters to the All-in-One SEO plugin with csv_import.
just add “all-in-ONE SEO” custom fields to the txt file. put the “key” in the first row, and the values below.
April 20th, 2008 at 2:14 pm
thanks! a lot.. this worked like a charm!
April 23rd, 2008 at 5:34 am
Hi Zack, thanks for the plugin. I’v not managed to get it to work yet though. After selecting my file and then clicking import I’m getting this message:
Import CSV
Warning: Cannot modify header information - headers already sent by (output started at /content/DesignerPlus/l/o/mydomain.co.uk/web/wp-admin/admin-header.php:16) in /content/DesignerPlus/l/o/mydomain.co.uk/web/wp-includes/functions.php on line 2448
Any ideas? As usual it’s probably something dead simple but I’ve just not worked it out yet. I think this site is on wordpress 2.0.4.
Thanks
April 24th, 2008 at 11:20 am
Just tried it out for 5 minutes but it looks really good so far !
April 26th, 2008 at 8:19 pm
How we can modify the plugin to import pages?
Thanks!
April 26th, 2008 at 8:38 pm
I’m not sure how much work would be involved in changing the code to import pages instead of posts. The line/function used to import the post is
$post_id = wp_insert_post($postdata);
I started looking into what function is used to create a page and I can’t seem to find it (granted, I only looked for about 5 minutes). If anybody has the patience to find it, let me know, maybe I can add an ‘import page’ feature.
April 28th, 2008 at 5:30 pm
Hi there -
I still can’t get this to work for me… I’ve tried on a few version of WP. In some of my field values I am using spaces - does that matter? Does white space matter at all?
thanks!
April 28th, 2008 at 6:16 pm
I’m having such a hard time with this. Can I send you my text file to take a look at? I have tried so so many different things and it is just not working.
I have changed my date format as suggested, and in fact I have changed tons of things. I am saving a CSV from excel, opening in a Mac text editor, replacing my commas with pipes, and then saving as a .txt. Any help is much appreciated.
<B
April 28th, 2008 at 6:47 pm
I got it now — If any Mac users are out there going from an excel CSV to a text file, export from excel as a CSV(Windows) file in the sace as options. Duh, I feel like saying to myself, hopefully this will save someone else some time. Plug in rocks!! Thanks for your work Zack.
April 28th, 2008 at 8:30 pm
Hey Michael & Zack,
I´ve tried to insert the proper “keys” in the txt file to pass values to the All in One SEO plugin…I want to pass value for theses variables in the plugin: title, meta description & metakeywords.
Can you help me achieve this? Just a small example to clarify which are the correct “keys”?
Thanks in advanced guys!
April 30th, 2008 at 4:23 pm
Any help here guys?
May 9th, 2008 at 4:41 am
There are no difference between post and pages just the “post_type” field which has to be “page”
May 10th, 2008 at 5:35 pm
Hello: I’ve been looking for something like this! Thank you! I try to import and get the message “The uploaded file could not be moved to …httpdocs/wp/wp-content/uploads/2008/05. 121″. What am I doing wrong?
May 10th, 2008 at 7:04 pm
Hi Loren,
wp-content needs to be writable by the server. Make sure permissions are right. Maybe that’s it.
Zack
May 14th, 2008 at 2:42 am
Hi!
I am interested in contributing to the development of your tool. What I’d like to have:
* possibility to import pages instead of posts
* control more columns than just the four you have.
* define default values for other columns
* column “id” to modify existing posts.
* export csv (with ids) for easy mass manipulation in excel. This export could happen automatically with every import.
Do you have a repository somewhere, where I could contribute?
Please contact me if you are interested in cooperation!
May 15th, 2008 at 7:08 am
Hi LemonHead
Thanks for offering! Your ideas are great. I don’t know what repository to host the project. I don’t know if this script really qualifies as a plugin to submit to Wordpress.org because it runs under the admin/import section and not /plugin. I could be wrong…it may not make a difference to Wordpress under what dir the script runs. Anyway, I say this because they (wordpress.org) use SVN to keep versions of plugins and maybe we could collaborate through that. If you have any ideas on which repository to use please let me know. This could really turn into a great project.
May 15th, 2008 at 1:40 pm
Great it works like a charm
Thanks a lot
May 15th, 2008 at 7:48 pm
And another one
* allow more flexible input format
I prefer to not publish my email in public, but I hope you can find it on the admin backend.
About the repository. So far I have not bothered to get my own repository running somewhere. WP.org seems like an easy solution, so why not have a try.
Btw, I don’t find an rss link for the comments. I would like to keep up to date!
Thx, lem.
May 16th, 2008 at 12:36 am
Hello,
Thanks for your great plugin first. Is it possible to have tag(s) support?
May 19th, 2008 at 5:47 pm
Now gave it some MVC, made the variables more local (I don’t like methods to communicate via class-scope variables), and made some things more logical (or what I perceive as more logical).
It’s going quite well, but now I am arriving at the tasty part, the process_post method, which at some point calls the WP function wp_insert_post(..). I am sure I can bite my way through, but I would be happy about some assistance and someone telling me what’s the idea behind all the lines of this function. Sometimes I think I can magically simplify things, but miss some of the original ideas which have been behind.
Another function which I don’t fully get is the get_tag() method. Is the user expected to put some XML tags into the input table?
Would be great if you can lighten me up a bit
June 8th, 2008 at 7:12 pm
Nice plugins. But, how about if I want to put tags in there ? how to make it.
For example :
wp_title|wp_post_date|wp_category|wp_content|tags|field2|field3
I want to make it like this :
wp_title|wp_content|wp_category|wp_post_date|tags1, tags2, tags3, moretags
June 18th, 2008 at 3:06 pm
Any way to insert custom slug/post_name?
I’d like to order posts by post_name (different than the sanitized post_title).
In my site’s scheme, post_title is the book’s title, post_name/slug is the book’s reference number.
June 24th, 2008 at 2:26 pm
Hi, looks like a great plugin.
I’d like to use it to import datafeed items with images. How would I add an image field into csv and connect it to the post (wp-content)?
thanks.
June 25th, 2008 at 6:12 pm
Hi,
I looked at discussion about All-in-one SEO plugin… How exactly txt line will look? Anybody can give an example?
…|wp-content|All-in-one SEO|tags
…|fun staff|Title: Post1, Description: test desc|test tag
????
Anybody can help please?
July 12th, 2008 at 11:48 am
Hey guys,
I am having issues while importing posts…for instance, whenever I have a new line or starting a tense on a different line the plugin assumes it’s a new post….any ideas on how to solve this?
Thanks a lot!
Nick
July 29th, 2008 at 8:15 pm
I tried to import post using rss/xml format but i had problem with the custom field. then someone suggested me to try this and voila! its working perfectly!
a million thanks to you zack.
August 4th, 2008 at 1:00 am
awesome work here. I do have a question though.
Do you know how to merge three cell columns together? ie: A, B and C
I have a csv file thats got 3 columns for different information but I need it all to go into one so I can add it into the wp_content column.
Any help is appreciated.
Thanks
August 12th, 2008 at 12:25 am
I think this is perfect for what I need… only problem is it’s not importing the content. Instead, it’s putting, for example from your sample, “My Post Title” and “Another Post” into the title and content fields.
I’m using Wordpress 2.6. Thanks a ton! If I can get this to work, you’ll have saved me hours of work!
August 12th, 2008 at 12:32 am
Ok, disregard my last comment. I must have had a something wrong. It’s working perfectly now! Thanks!
Do the spaces between the text and the pipe have to be spaces, or are tab’s ok?
Thanks again!
August 22nd, 2008 at 12:05 pm
All that is needed to make a “post” a “page” is one variable
online 292 of your script change:
$post_type = “post”;
to
$post_type = “page”;
im no php whiz
but this seemed to work! i tried it with your test csv after only changing that one line and the sample shows up in my pages area of wordpress
by the way .. you ROCK thank you for posting this plugin i have been wanting something for this forever!
August 24th, 2008 at 9:21 am
Is there a limit to the characters in wp_content
mine contains the following:
REBECCA is between 20 and 30 and is in a relationship (but not yet engaged or married). Rebecca LOVES the brand-name DiamondGeezer.com. and described the Diamond Geezer web site as EXCELLENT.She added ……TextPad loads an entire file into memory when you edit it, so the original file is not changed until you save the changes. You can opt to keep the original file as a backup when saving changes, and to keep it locked while you edit it.
But ends after She added ……
August 25th, 2008 at 8:17 am
Hi
This looks really great… just one, probably dumb question… how do I get a csv file to be pipe delimited?
August 25th, 2008 at 8:24 am
aarg dont worry… typically after spending 2 hours online etc to figure it out, I got it together after writing this note… apologies!