get_terms vs. get_categories: does it matter?

As you dive into WordPress, you’ll find that WordPress has a lot of wrapper functions. For instance, there’s add_theme_page that’s just a wrapper of add_submenu_page. That’s certainly not the only example (add_submenu_page itself has a bunch of wrappers, in fact). If you look at the source for get_categories(), you’ll see that it too is a wrapper for get_terms() (I just learned that myself, so thanks!).

I find that the taxonomy-related functions are some of the most convoluted. A lot of them take very similar arguments and return similar things with little differences. In this case, get_terms() has a name__like parameter that get_category() doesn’t. There are probably other little differences too.

As a personal preference, I try to use get_terms() as much as possible. In some cases, like add_theme_page that’s the recommended function (presumably so WordPress could make changes to the Theme page and keep that function working), but in other cases like this one, I don’t think it makes much of a difference. If nothing else, the familiarity helps me do more with it faster. However, some of the functions that return HTML lists like wp_list_categories() can be useful at times.

Leave a Comment