custom taxonomy – wp_delete_term() takes forever to run, even for lowest depth terms with just a few objects

Question

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:

wp_delete_term(1140, 'product_cat')

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?

0
Kristian Filo 6 months 2021-06-16T09:13:35-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse