I have a simple text file with a list of words (Berlin Hamburg Stuttgart ...) and so on. They are cities of germany an nearly 2000 counted. I need everyone of them as a category in my wordpress site and looking for the best way to achieve this. Is there a faster way than to create every single category manually from the dashboard?

Thanks for your help!


Assuming you have a nice list of your Words, you could easily create an array with them, doing a little data manipulation.

Afterwards you can loop throug your $array and insert the Term accordingly:

$yourcities = file($filename, FILE_IGNORE_NEW_LINES); // all your valuesfrom the .txt file

foreach( $yourcities as $thiscity ) {

        $thiscity, // the term, in your case the name of the city
        'category', // the taxonomy, in your case category
            'description'=> '', // if available
            'slug' => '', // leave blank if not available
            'parent'=> $parent_term_id // if you do it hierarchical, be sure to insert the parent ID here

  • Thank you for your suggestion. But how do I have to do it? I have just a text-document with a list of words. What should I exactly do with it? – user45836 Jan 29 '14 at 11:14
  • Try doing it like this. I updated the answer to include this method :) – fischi Jan 29 '14 at 11:15
  • Okay and where do I have to place the code exactly and store the txt. file? – user45836 Jan 29 '14 at 11:19
  • You can store the code in your functions.php or create a plugin for it. The easiest way would be to upload the .txt into the same folder. Be sure to execute the code only once! – fischi Jan 29 '14 at 11:23
  • 2 more things: It's not the default category for posts, it's the taxonomy=ad_location from the posttype=ad. The text-file is calles staedte.txt and located now in the same folder like the function.php. How does the code looks now for me? – user45836 Jan 29 '14 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.