I'd like to import a long list of categories into ExpressionEngine and create new categories. Is there an easy way to do this, either via add-on, or some handy PHP code?
1 Answer
Use DataGrab -- http://devot-ee.com/add-ons/datagrab -- and import with a spreadsheet. If you have only one level for categories, it's super easy. If you have category levels or categories with same name, it's a little more complicated.
If you have levels, your spreadsheet (csv is best, IMO) can be created safely following these steps.
- In EE, create the first top-level category. Note its cat_id.
- Export the exp_categories table from your database (or create a spreadsheet with the exact same columns as that table).
- Add a new row for a new category (best to keep it in order for sanity's sake). If the next category is a child of the first category your entered in EE, make sure to the parent category's id as this category's parent_id. Also, this category would have a cat_id one number higher than the first one you created.
- Keep adding rows like that.
If you have categories with the same name, make sure to give them a unique cat_url_title.
-
I have datagrab, and as far as I can tell, you can only import categories as part of importing an entry. So, I guess I could import one entry that had all the categories I wanted to import, and then delete that entry... but even then, it seems pretty limited, and doesn't do parents, category groups, etc. Jul 31, 2013 at 23:53
-
Or really you could skip datagrab and just import the updated spreadsheet directly to the database. Just export that table in .csv format first. Jul 31, 2013 at 23:56
-
Fair enough -- a CSV import does seem like a pretty straightforward way, even if it does require a lot of DB knowledge to be able to use it :) Jul 31, 2013 at 23:59