Recently while working on a large-scale WordPress site, I encountered a tricky situation. I had quite a lot of locality data for Australian states, suburbs and LGA’s (Local Government Areas). We are talking about tens of thousands of items in the database.
At first, I made all of these custom taxonomies hierarchical. Part of the reasoning was that users could visually select values from the meta boxes (hierarchical taxonomies look better). Initially, it wasn’t a problem, but as more data was added, saving posts took forever, I was getting timeouts, and queries were slow.
If you are reading in hopes of a solution that allows you to keep using hierarchical taxonomies with tens of thousands of items, I am sorry to disappoint you.
The solution was to make all of my large taxonomies non-hierarchial. Literally setting the argument for the taxonomy to false.
"hierarchical" => false,
I leveraged the Advanced Custom Fields plugin to create the taxonomy hierarchy using post relationships for those uses where I need a hierarchy. It’s not an ideal situation, but it works.
Sadly, WordPress has had this issue for several years now, and because of the way taxonomies work, I don’t think it will be fixed any time soon.
TL;DR — hierarchical taxonomies will not work properly for thousands of items. Use non-hierarchical taxonomies instead.