How to List Parent Term Links for Custom Taxonomy With & Without Children?

I have a Custom Post Type of “projects”, that is categorized by a Custom Taxonomy of “industry”, which is heirarchical. Projects & sub-projects are assigned to the industries. For Example, the “Academic” industry contains, three sub-industries of, University, Community College, & K-12. I need to display the list of projects.

For Example:

Academic
  -University
  -Community College
  -K-12
     -- Gordon Elementery
     -- West Lake High School
          --- Gymnasium
          --- Admin Building
          --- Cafeteria
     -- Jefferson Elementary

Right now, it lists all projects including the subprojects

Basically, if the term has no “sub-terms” it links to the single.php for that term. I also need it to just list the parent term, should that term have “sub-terms” or child terms.

I’ve played around with get_term_children() but just can’t seem to figure out how to work this out. Any suggestions would be greatly appreciated. Thanks

2 Answers
2

Here is some basic setup for the function that MavBzh mentioned.

<?php
$args = array(
    'title_li'          => '',
    'taxonomy'          => 'industry',
    'show_option_none'  => '',
);
?>

<ul><?php wp_list_categories( $args ); ?></ul>

Leave a Comment