get_terms ‘number’ parameter does not appear to work

So here’s some info for any other people with this issue.

get_terms will not use the number parameter under certain conditions, such as if you pass in a parent parameter or if the hierarchical parameter is true. In these cases I have tried two workarounds, neither very good.

  1. You can call get_terms then do an array_slice on the results afterwards. However if you have a ton of taxonomies then WordPress can run out of memory during the get_terms call, which was my original issue.

  2. You can hook into the filter terms_clauses and force the get_terms call to use a LIMIT in its sql call. However this applies to all calls of get_terms across WordPress and not just the one in my custom code, and I don’t want to cause unintended consequences.