Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there any way to get only parent terms from custom taxonomy or category?

share|improve this question

2 Answers

up vote 9 down vote accepted

Yes, just pass in the parent parameter to get_terms when you call it, as Michael pointed out.

$myterms = get_terms( 'taxonomy_name_here', array( 'parent' => 0 ) );

Will return all terms that have a parent value of 0, ie. top level terms.

share|improve this answer
It returns empty array for custom taxonomies :( – Mamaduka Aug 2 '11 at 13:14
Are the terms in that taxonomy associated with a post(or custom type)? If not, you'll need to pass along the hide_empty parameter, setting that to 0 also, so you're able to see terms currently not used. – t31os Aug 2 '11 at 13:25
Thanks, need to dig into other args too – Mamaduka Aug 2 '11 at 14:15

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.