I'm trying to show both the parent and child categories of my custom post type separated by the first letter of the category
What I have.
A.
Apples
B.
Bananas
C.
Coconuts
What I want
A.
Apples<br />
-Red<br />
-Green<br />
B.
Bananas
C.
Coconuts
Here's the code I have now. I just need it to show the child categories too. Thanks in advanced.
<?php
$list = '';
$args = array(
'hide_empty' => true, // Set this to true to hide terms with no posts
'hierarchical' => true,
'pad_counts' => false
);
$tags = get_terms('type',$args);
$groups = array( );
if( $tags && is_array( $tags ) ) {
foreach( $tags as $tag ) {
$first_letter = strtoupper( $tag->name[0] );
$groups[ $first_letter ][] = $tag;
}
if( !empty( $groups ) ) {
$index_line = '';
foreach( $groups as $letter => $tags ) {
$list .= '<h4><p id="' . apply_filters( 'the_title', $letter ) . '"><strong>'. apply_filters( 'the_title', $letter ) .'</strong></P></h4><hr><ul>';
foreach( $tags as $tag ) {
$name = apply_filters( 'the_title', $tag->name );
$list .= '<li><a href="' . get_term_link( $tag ) . '" title="' . sprintf(__('View all posts tagged with %s', ''), $tag->name) . '">' . $tag->name . ' </a></li>';
}
$list .= '</ul>';
}
$list .= '';
}
} else $list .= '<p>Sorry, but no tags were found</p>';
print ($index_line);
print ($list);