How to Get Top Level Categories / Taxonomy in WordPress

Snippets by IsItWP

Do you want to get top-level categories / taxonomy? The trick is to have hide_empty=0 in your snippet. In this article, we’ll show you how to list top-level categories / taxonomy in WordPress.


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

$args = array(
    'type'          => 'post',
    'orderby'       => 'term_group',
    'hide_empty'    => 0,
    'hierarchical'  => 0,
    'parent'        => 0,
    'taxonomy'      => '..if you are using a taxonomy instead of a category'
get_categories( $args ); 

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes or 7 best WordPress contact form plugins.

[code] 'post', 'orderby' => 'term_group', 'hide_empty' => 0, 'hierarchical' => 0, 'parent' => 0, 'taxonomy' => '..if you are using a taxonomy instead of a category' ); get_categories( $args ); ?>[/code]

Comments   Leave a Reply

  1. How would you get the 2nd level of the taxonomy?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!