Importing Posts from CSV file into Wordpress

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:

  1. Download CSV_Import class from me. csv2 post.
  2. Unzip and up load the file called csv.php to /wp-admin/import/
  3. 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.
    CSV to post
  4. In admin panel , go to Manage, Import, choose CSV
  5. The rest is pretty self explanitory, upload file, pick a user, and voilá

93 Responses to “Importing Posts from CSV file into Wordpress”

  1. me says:

    Bob,

    Having the same problem too. Any solution yet?

    How to add new line for a single long post?

    Any advise?

  2. peter says:

    this plugin rocks. is it able to add tags? wp_tags

  3. Mike says:

    I was thinking it would be nice if we could modify this to work with WP MU so that instead of uploading to a post or article, we could upload to a new blog subdomain. Is this too far fetched based on the current state of the plug-in?

    Great plug-in regardless, truly a unique and completely useful tool in it’s current form, thank you so much!

  4. M says:

    Script is working fine, however not adding any tags to the posts imported.

    Does anyone know the exact variables to use to make sure tags can be added?

    I tried both “wp_content” and “the_tags”

    Thanks. Great script.

  5. Adem says:

    I figured it out. Thanks.

    For those of you that is having the same problem as me which is it imports wrong values, you need the header part of the csv which is:
    wp_title|wp_post_date|wp_category|wp_content|field1|field2|field3

    put that on the header and you should be fine.

    thanks for the script, it works very well and it is very useful.

    Adem

  6. Andrew says:

    Thanks for your wok on this script. It works beautifully. One problem I’m having is with line breaks within the wp_content field. Shouldn’t I be able to have line breaks within the pipe delimited field? Let me know if I’m missing something obvious. I am importing data from a pMachine site. Do I need to replace all CRs and LBs with HTML tags? Thanks.

  7. glenn says:

    Im trying to find a way to get my posts from, b2E over to WP. This is a error I came up with when trying to use the CVS file per your instructions.

    Fatal error: Cannot redeclare kaltura_find_post_widgets() (previously declared in /hsphere/local/home2/extsieg/siegrist.nu/wp-content/plugins/all-in-one-video-pack/all_in_one_video_pack.php:73) in /hsphere/local/home2/extsieg/siegrist.nu/wp-content/plugins/all-in-one-video-pack/all_in_one_video_pack.php on line 73

  8. I’m so glad I found your CSV import tool. I’m just now putting my text file together. I’m moving an old Squarespace blog to my own WordPress blog. One of the entries, however, has a user comment. How do I upload comments written by other people using your utility?

  9. Tim says:

    Hi Zack,

    Thanks for the plugin; I installed it with no problem.

    My question is how do I add the extra fields to my posts? I assume the new code goes into single.php?

    I am not fluent with PHP – I read it but I can’t write it – so if you could point me to examples I can copy and paste that would be great.

    Thanks for your help – Tim

  10. Heikki says:

    I have a strange problem. I have made a csv file just like the example and I even tried the example file but no help…

    The script converts all posts into a categories and ignores the content. There’s the title as a category of the post, as a title and as the content.

    And if not weird enough, in the title’s there are strange characters after every letter of the title.

    What am I doing wrong here?

  11. Tim says:

    Great plugin! The only problem I’ve had is importing large files. I know the max is 10mb but even 3mb files are timing out for me. Small files work fine.

  12. Lingvemulo says:

    Hi – I’d like to reiterate the request for code to import tags… Have tried “wp_tags” and it doesn’t work. Is there something we can do? If I can’t import tags with my 200-some posts I’ll have to add them by hand, which kind of makes an automatic import moot.

    Thanks!

  13. Jonathan says:

    I’m having the same problem as Andrew. In the wp_content field, each line break is treated as a new post. I set up 20 posts for import, but it recognized 296. I’m using WP 2.7

    Jonathan

  14. Samrs says:

    I just installed this plugin and it imports the data very well. Thank you very much. The one question I have is how to get the categories to work. The imported data is creating a new category and naming it what ever the wp_title name is. It appears some others have experienced this as well. Do you know a solutions?

    Many thanks

  15. [...] I found a fantastic plugin which allows you to import posts directly from a CSV file. The CSV2Post plugin provided by Zach is an excellent way to automate your postings. The cool little plugin [...]

  16. drage says:

    I liked this… thanks Zack!
    And how about wp_tags ?
    Is it a great problem?

  17. Jukka says:

    Does it support multiple categories ?

  18. jean says:

    Hello,

    I have two questions

    1. how can I show Umlauts correctly
    2. html and import tables correctly

    Thanks

  19. Jukka says:

    Jean,

    About umlauts: I did try importing posts with special letters in their topics, and they work if you make sure that .cvs file is in UTF-8-format. My Excel exported .cvs in ANSI-format, so I used Notepad++ to convert it to UTF-8 and voilá!

  20. jean says:

    in post, is German umlauts ä, ö, ü, are not displayed correctly

  21. Higgins says:

    really like yr importer – use it a lot. Haven’t tested uploading & importing pages (w tweaking t post_type variable) but I’ll give it a try & post my experience.

  22. Hello,

    has this plugin urf-8 import support?

    Thank you!

  23. What happen if I have many categories with same name and with different parents.
    like United States(parents)>California>Images
    similarly
    United States(parents)>Alaska>Images
    So images is same if I made my data
    My Post Title|2007-12-31 23:59:59|images|Long post text|value|value|valaue
    Whic will put it in any images, so how can I make it that it should put that categories in proper parent cateogory.
    I tried.
    My Post Title|2007-12-31 23:59:59|alaska > images|Long post text|value|value|valaue
    But it create new category of Alaska > Images, and go in that cateogry.

    Anyone if could through some light.
    regards

    Kamal.

  24. Goran says:

    Hello, I also have problem s with non-English characters.
    Characters č, ć, ž etc. are all converted to ? or square a.
    This is not the case when importing from wordpress export file. Have anyone find a solution? jean?
    Thank you

  25. Ajay Jain says:

    It seems to be good script.

    But it should support comma delimited csv file becuase while saving the file as csv file in ms excel there is no option to save it live pipe delimited csv file.

    Regards,
    Ajay

  26. aukseo says:

    Looking at the code to change to import into pages you need to change this line

    $post_type = “post”;

    to

    $post_type = “page”;

    will be testing now

  27. Goran Milo says:

    how do you add username or $user_id for each post in the cvs?

    wp_title|wp_post_date|wp_category|wp_content|dc:creator|field2|field3
    aint doing the trick for me.

  28. Nauman says:

    I have the same question as Kamal has (73), how to handle parent / child categories in import?

  29. wpnewbie says:

    Just wondering if there is any solution to the TAG issue… This is pretty awesome, but adding tags would make it even better!

  30. volcomjon says:

    Hi zack – great plugin, and is working well – until it comes to long posts (with paragraphs) – I have read that other people are also experiencing the same problem with the script breaking the posts up at each paragraph line break, therefore generally screwing up the entire import.

    please please please can you help us out with this one as I have tried a couple of different methods using preg_replace and it is still doing the same thing.

    unfortunately I cant go through every single post taking these line breaks out, and so there must be a solution.

    your help would be very much appreciated.
    Cheers

  31. volcomjon says:

    ok – I have found where the problem lies with splitting the import into separate arrays where line breaks appear – it is because of the use of the file() function – which splits arrays with every new line break. – now – I have found an optional flag which attempts to ignore these line endings, but it doesnt seem to work.

    I believe it also has something to do with the encoding of the csv file you are uploaded – e.g. – unix, windows or mac format, as the line endings are different in each version.

    here is what I have found in the php manual – if anyone can shed some light on this – it would be awesome

    http://uk2.php.net/function.file

  32. Mike says:

    Like everyone else, I need some of the same things.

    1) Ability to add tags
    2) Fix the line break issue
    3) Ability to change slugs

    Any updates coming?

  33. Mike says:

    Addendum to my previous post:

    I’ve figured out how to use this for pages instead of posts, and to define a parent page, as well as a page theme.

    All that’s left is to figure out how to fix the linebreak bug. Any suggestions are welcome.

    For those that want to use this for pages, with a page parent:

    on line 292, change:
    $post_type = “post”;
    to
    $post_type = “page”;

    To define a page parent:
    Below $post_type, add:
    $post_parent = “”;
    Input the ID of the page you want to be the parent of your imported page(s).

    If you want to use a custom template, simply add a field to your CSV that is _wp_page_template, and define it with whichever .php page you want for your template, ie; page.php

    Hope that helps those that are trying to do what I am. Now, if I can figure out that pesky linebreak bug, I’ll post again.

  34. Mike says:

    I think I found a bug.

    Any field that has any form of HTML link in it, gets imported in quotes.

    While there’s no quotes around the fields in the CSV, something in the script is adding opening and closing quotes, presumably to escape the quotes in the links. Any ideas?

  35. Goatseo says:

    is it planned a wordpress bundle for XLS importing?

  36. jojo says:

    Hi Zack
    Thanks for this great script, that will save me dozens of hours :-)

    Yet, I still have one question : is it possible to define the permalink of each post ?

  37. Sushi says:

    How do you make a post go under a parent category?

  38. Yip Bop says:

    Hi, How can I enter a code in the wp_content field such as:
    [code]name,12,260,""[/code]

    When I import, it pasts in the content [code]name,12,260 and not the rest of the code.

    Also, I am getting a " before the title on the post

    Thanks for your help.

    Yip

  39. Herry says:

    [Comment Import]

    Hallo Zack,

    i have the same question as Carl Eric Johnson (Nr. 58). Can you tell us about that?

    Thanks for your script!

  40. windracer says:

    Thanks for a great tool! I used this and your category importer to move 525 entries exported from a SQL database into WordPress.

    For those of you having problems with line breaks, try replacing any CR/LF combinations (ascii 10 and 13) with the ” tag. The importer will obey that and you’ll get the proper breaks in your post content. This worked great for me.

  41. Raj says:

    Hi,

    I’m using Wordpress 2.8.2 (latest) version.

    I’ve installed the “import” successfully and can see it under Tools>>Import

    However, when I tried to upload the sample csv file, I’m got below error..

    *************************************************
    Import CSV

    Sorry, there has been an error.

    File is empty. Please upload something more substantial.
    *************************************************

    Any idea guys, Zack.. Please help

  42. mugger says:

    Lines truncate at high-ascii characters.
    I renamed |field1|field2|field3 to |Price|More Info|Image where
    Price = $nn.mm
    More Info is hyper-text link
    Image is absolute URL. (Try relative path later.)
    None of these appear in PostEdit or blog.

    Without those fields, import is worthless to me.
    How might I rescue this?

  43. malibu says:

    Hi,Zack.

    I have a question.

    The future post doesn’t work.

    [wp_post_date]
    2008-12-31 23:59:59→OK!
    2009-11-13 23:59:59→reserved→ 11-14 still “reserved”.

    This is only from csv2post.

    please help me! please.

Leave a Reply