8

I have a custom hierarchical taxonomy setup for a conference website. The top-level terms in this taxonomy are Dates, which have child terms representing session slots on that date. I'm trying to figure out how to get a list of the top-level terms within the taxonomy, that is I only want the terms that are Dates, not the terms that are sessions. Is this possible using get_terms()?

2 Answers 2

22

Try to pass 0 for parent argument in get_terms().

parent (integer) Get direct children of this term (only terms who's explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.

3
  • +1 - This is the answer you're looking for... ;)
    – t31os
    Commented Feb 1, 2011 at 11:55
  • This worked for me! But why doesn't this function have a "depth" argument like other Wordpress get functions?
    – Jeff K.
    Commented Oct 18, 2011 at 0:35
  • @Anatidaus who knows... btw I won't say depth is that common.
    – Rarst
    Commented Oct 18, 2011 at 8:56
-1

See http://codex.wordpress.org/Function_Reference/get_terms.

Use the hierarchical = 0

$my_taxonomy = get_terms('my_taxonomy', 'orderby=count&hide_empty=0&hierarchical=0');
1
  • nope. hierarchical=0 doesn't work. The better way is parent=0 Commented Sep 16, 2017 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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