0
votes

I was wondering if you could help me display a taxonomies child links, for example, I have a custom post type of "courses" with a custom taxonomy of "study_type" and categories like "security", "professional" etc. Currently I am correctly displaying the category title and description. I need to know how to get a permalink for the courses that fall into the categories and display them underneath the category description. Thanks for any help or advice you have to offer. Here is me code:

<?php
//list terms in taxonomy
$types[0] = 'study_type';

 foreach ($types as $type) {
 $taxonomy = $type;
 $terms = get_terms( $taxonomy, '' );
 if ($terms) {
  foreach($terms as $term) {
    echo '<h2>'.$term->name.'</h2>';
    echo '<p>' . $term->description . '</p>';
    //This is where the links should be
 }
 }
 }
?>
1

1 Answers

0
votes

use get_term_children

<?php
//list terms in taxonomy
$types[0] = 'study_type';

foreach ($types as $type) {
 $terms = get_terms( $type, '' );
 if ($terms) {
  foreach($terms as $term) {
   echo '<h2>'.$term->name.'</h2>';
   echo '<p>' . $term->description . '</p>';
   //This is where the links should be
   $termchildren = get_term_children( $term->term_id,  $type );
   if($termchildren){
    echo '<ul>';
    foreach ( $termchildren as $child ) {
     $term = get_term_by( 'id', $child, $taxonomy_name );
     echo '<li><a href="' . get_term_link( $term->name, $type ) . '">' . $term->name . '</a></li>';
    }
    echo '</ul>';
   }
  }
 }
} ?>