I want to insert hundreds of categories, structured hierarchically.
Any suggestions on how I could do it in a batch mode?
Thanks.
Leave a Reply
You must be logged in to post a comment.
I want to insert hundreds of categories, structured hierarchically.
Any suggestions on how I could do it in a batch mode?
Thanks.
You must be logged in to post a comment.
This is main function of the import process.
}
First I need a object that contains the category. In this case, it should be a object, but could be easily adapted to deal with an array.
I start the process with providing the object and start a level 0 :
You could easily change it create a custom taxonomy by changing
'category'
inwp_insert_term
andwp_update_term
functions.In my case, I had for each category, and ID and a slug provided, because I was importing from another database. I don’t know your specific, so you may need to adapt it.
Hope this could help, feel free to ask and comment.
EDIT TO ADD CONTEXT INFORMATION :
I had used this function in a template file, instead of the regular loop, so I just lauch the import process by displaying a particular page of my page and I output the data with
echo
so I have an instant and clear view of the structure of my categories, see if it looks OK.As you see, the function also could update data so if you change something in your categories file (name for example), you just need to run it again and data will be update.
What it does NOT do is modifying structure : if you delete a category from the imported file, it will not be deleted on the WP structure. It does not compare data, just parse it, and for each item create it if not present, update it if present.
To start testing, I just changed one line :
by
so the import stops right after the first level (parents) categories. If everything’s fine at this point (name, hierarchy) you could remove the conditionnal number.
To import data i just use :
Hey Guys sorry to post in a very old post but i found one that worked for me after several hours of surfing the web, Hope this helps someone in the same situation.
I use https://wordpress.org/plugins/bulkpress/
I know it says it hasnt been test for the new wordpress version but works for me as of 4/1/16
Would this do the trick?
http://wordpress.org/extend/plugins/category-import/