Is there a quick way to add a list of countries as terms to a custom taxonomy called “Country”?
Is there an existing import file, SQL script ect…
I don’t want to be there all day manually adding them.
Any ideas would be great.
Is there a quick way to add a list of countries as terms to a custom taxonomy called “Country”?
Is there an existing import file, SQL script ect…
I don’t want to be there all day manually adding them.
Any ideas would be great.
You must be logged in to post a comment.
Try this. Note that I found this country array online and cannot vouch for it’s accuracy. Also, I’ve set the taxonomy to the “country” taxonomy. Change all instances of that if it does not match your specific taxonomy name. You can add this to your functions.php file in your current theme. Reload WordPress and it should add them. Once they are added, delete this code. I did put a check in there to make sure they aren’t added twice.
This is for Algerian wilayas & communes, for the full code check this repo: https://github.com/ilyesrd/Insert-Wilayas-Communes-to-custom-taxonomy-in-wordpress
You can make your own script to import them using wp_insert_term.
@tollmanz did a nice job, this way works. I have now just updated it with the more actual list of countries and in lowercase.
Source of countries: https://github.com/umpirsky/country-list
I just want to add that if you see a 404 page after you add this taxonomy for a post type, then you simply put
flush_rewrite_rules();
in the register taxonomy section.For example: