You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Functions that use the WP_Term_Query class such as get_terms() have hierarchical => true set as a default. This can be problematic for taxonomies that have large number of nested terms. When hierarchical is set to true, the class calls get_term_children(), which in turn calls itself recursively. For instances where there is a small number of terms (less than 1000, it seems) this isn't an issue, but on a large number of nested terms, thousands of additional queries are run, which can slow pages considerably.
On one project a taxonomy was set up as nested terms in a 'location' taxonomy. This included Country -> State -> County -> City . The number of terms was somewhere around 60,000, which slowed archive pages to a crawl as it parsed all of those terms recursively with new queries.
I haven't determined the limits for a recommended threshold for depth or number of terms that would result in slower queries, but I'd like to propose we mention in the best practices to avoid using hierarchical => true on large or deeply nested taxonomies until this recursive functionality is replaced in core. Curious what others think.
The text was updated successfully, but these errors were encountered:
@bengreeley appreciate the post. I took a brief look at the get_terms method in WP_Term_Query and see what you're saying. However, the function is pretty dense (800+ lines long) so it was hard to follow.
I did see some caching in _get_term_hierarchy which is called by get_term_children.
I'd love to see a PR written with this. I also think it would be worth addressing this in core.
I am working on a project that sale car parts and i have created year/make/model with Toolset taxonomy but after i entered all the cars and models it has become very slow to load the shop page. I trying to following post but i am not too good in wordpress. Please is there anyway you can assist me.
@ganusoft This is not a support forum, it's an issue tracker for best practices documentation regarding WordPress development in general. If you're looking for direct user support, I'd encourage you to visit the official WordPress support forum.
Functions that use the
WP_Term_Query
class such asget_terms()
havehierarchical => true
set as a default. This can be problematic for taxonomies that have large number of nested terms. When hierarchical is set to true, the class calls get_term_children(), which in turn calls itself recursively. For instances where there is a small number of terms (less than 1000, it seems) this isn't an issue, but on a large number of nested terms, thousands of additional queries are run, which can slow pages considerably.On one project a taxonomy was set up as nested terms in a 'location' taxonomy. This included Country -> State -> County -> City . The number of terms was somewhere around 60,000, which slowed archive pages to a crawl as it parsed all of those terms recursively with new queries.
I haven't determined the limits for a recommended threshold for depth or number of terms that would result in slower queries, but I'd like to propose we mention in the best practices to avoid using
hierarchical => true
on large or deeply nested taxonomies until this recursive functionality is replaced in core. Curious what others think.The text was updated successfully, but these errors were encountered: