Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'hierarchical => false' When Using WP_Term_Query on Large Taxonomy #199

Open
bengreeley opened this issue Sep 6, 2017 · 3 comments
Open

Comments

@bengreeley
Copy link
Contributor

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.

@tlovett1
Copy link
Member

@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.

@ganusoft
Copy link

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.

@ericmann
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants