Display Only Top-Level Parent Categories – WordPress

Old People, Probably Grandparents

If you are using a loop to list all your WordPress categories or terms in a custom taxonomy and you only want to display the top-level ones, here is how you do that. The trick is in getting the “parent” parameter, which is set to “0” for all top-level terms and categories. So to start a foreach loop and display all the terms that are parents, use this code:

Pretty simple, right? Nothing too complicated there. Now, what if you wanted to list all parent categories and link to their archive pages? We can do that! Here is the code:

There you have it! Easily link to all the top-level (parent) terms or categories in your custom taxonomy. Nothing too complicated here. Let me know if this helped you in the comments, or you can reach me on twitter @brianjonline.

About Brian Johnson

Brian Johnson is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.