custom taxonomy – wp_delete_term() takes forever to run, even for lowest depth terms with just a few objects
I need to completely remove hundreds of
product_cat terms based on my conditions with PHP.
wp_delete_term() should do the job just fine, and it basically does, but it takes forever to complete.
For example, I have a product category ‘my-test-category’ (e.g. ID 1140) that only has 1 product and is at the bottom of the hierarchy tree (it doesn’t have any more child terms). Running this code:
took more than 100 seconds to complete and I really don’t know why. PHP error log is empty.
However, sometimes it randomly runs just fine even with larger categories (e.g. 50 product category runs in 15 seconds or so). It is reasonable, but still very slow since removing the same product category from WP dashboard seems to run much faster, sometimes even less than a second.
What could be the bottleneck here?