Search code examples
wordpresstaxonomywp-list-categories

Remove link in wp_list_categories list


I'm displaying a hierarchical list of my taxonomy "fachbereiche" using following code:

$args = array(
  'taxonomy'     => 'fachbereiche',
  'orderby'      => 'name',
  'title_li'     => '',
  'feed_type'       => '',
  'child_of'     => 12
);
?>

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

The displayed list is almost good, only problem is that every taxonomy list-item is wrapped in a link-tag and links to a single page of the taxonomy (which I don't have and want). How can I prevent the lists from being wrapped in an a-tag?

The output of the list in the frontend


Solution

  • What you want is get_term_children().

    <?php
        $term_id = 12;
        $taxonomy_name = 'fachbereiche';
        $termchildren = get_term_children( $term_id, $taxonomy_name );
    
        echo '<ul>';
        foreach ( $termchildren as $child ) {
            $term = get_term_by( 'id', $child, $taxonomy_name );
            echo '<li>' . $term->name . '</li>';
        }
        echo '</ul>';
    ?>