wordpress

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:

  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á

|

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

  1. Your Seventh Loyal Reader Says:

    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.

  2. Your Seventh Loyal Reader Says:

    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

  3. admin Says:

    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.

  4. michael Says:

    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.

  5. admin Says:

    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.

  6. Nick Says:

    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?

  7. admin Says:

    Hey Nick,

    I’m currently adding support for cats/subcats. Check back.

  8. michael Says:

    thanks for the update Zack,
    you saved me hours of mindnumbing work.

  9. Nick Says:

    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. ;)

  10. Nick Says:

    Any news Zack? :)

  11. admin Says:

    Hey Nick, see the new post

  12. Nick Says:

    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

  13. Nick Says:

    Actually, would be great if you could provide a quick overview of how we’re supposed to use the extra fields & excerpts columns…

  14. michael Says:

    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.

  15. logan Says:

    thanks! a lot.. this worked like a charm!

  16. Adam Says:

    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

  17. nevergivemyname Says:

    Just tried it out for 5 minutes but it looks really good so far !

  18. ImportingPages? Says:

    How we can modify the plugin to import pages?

    Thanks!

  19. admin Says:

    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.

  20. Your Seventh Loyal Reader Says:

    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!

  21. Your Seventh Loyal Reader Says:

    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

  22. Your Seventh Loyal Reader Says:

    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.

  23. Nick Says:

    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!

    :)

  24. Nick Says:

    Any help here guys? :)

  25. ImportingPages? Says:

    There are no difference between post and pages just the “post_type” field which has to be “page”

  26. Loren Says:

    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?

  27. admin Says:

    Hi Loren,

    wp-content needs to be writable by the server. Make sure permissions are right. Maybe that’s it.

    Zack

  28. lemon.head Says:

    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!

  29. admin Says:

    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.

  30. Joe Says:

    Great it works like a charm
    Thanks a lot

  31. lemon.head Says:

    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.

  32. Max Says:

    Hello,

    Thanks for your great plugin first. Is it possible to have tag(s) support?

  33. lemon.head Says:

    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 :)

  34. dewaji Says:

    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

  35. Lionel Chollet Says:

    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.

  36. Max Says:

    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.

  37. Max Says:

    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?

  38. Nick Says:

    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

  39. kamu Says:

    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.

  40. Mike Smith - Bootstrapping Blog Says:

    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

  41. Frank Says:

    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!

  42. Frank Says:

    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!

  43. Marc Juneau Says:

    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!

  44. DiamondGeezer.com Says:

    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 ……

  45. chantal Says:

    Hi

    This looks really great… just one, probably dumb question… how do I get a csv file to be pipe delimited?

  46. chantal Says:

    aarg dont worry… typically after spending 2 hours online etc to figure it out, I got it together after writing this note… apologies!

Leave a Reply

You can leave a response, or trackback from your own site.

About

This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.

Contact

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla eu neque. Integer nec justo. Morbi odio metus, mattis non, venenatis ac, molestie at, justo. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla eu neque. Integer nec justo. Morbi odio metus, mattis non, venenatis ac, molestie at, justo.