Poor get_category_children() performance; rewrite to use get_term_children()
|Reported by:||_timk||Owned by:||ryan|
I'm working on a WordPress site with a few thousand categories. The categories are structured a bit, with one master category, a few organizational subcategories, and then the bulk of the remaining categories under those.
I'm looking to get a list of children for one of the middle-tier categories. Running get_categories() with the 'child_of' parameter calls get_category_children(). This call hits the 30-second server time limit. Outside the web environment, get_category_children() takes around a minute and 40 seconds to build a list of 589 categories on a relatively powerful desktop PC.
I'll attach a revised, non-recursive implementation of get_category_children() that uses get_term_children() and runs several orders of magnitude faster than the original in my environment. It returns almost instantly.
Change History (10)
- Component changed from Template to Taxonomy
- Owner changed from anonymous to ryan