Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm fairly new to wordpress and am coming across new things each day - one was today when I happened across get_terms and noticed that it was basically the same as get_category.

Any particular reason to use one or the other? Is there something that I'm missing?

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
add comment

One of the most important (and not very obvious) differences between get_terms() and get_categories() is that get_categories() is a wrapper function for get_terms('category'). This means that you cannot get custom taxonomies with get_categories() and must use get_terms() instead.

share|improve this answer
    
Doh, this may not be true. Please disregard until I get an opportunity to verify a previous issue I ran in to. My apologies. –  Brent Clark May 29 '12 at 18:58
1  
Did you see the accepted answer that already explains this? –  Chris_O May 29 '12 at 23:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.