Taxonomies are great to group and organize  content. We’ll take a look on how to make an A-Z list of entries in a given taxonomy in WordPress. 

When we build Indiemondo we made a taxonomy for tagging films up with festivals. With over a thousands festivals simply making a long list and expect vivistors to browse thorugh was a no go.

We wanted to things:

  • Grouping festivals by first letter
  • Making an easy in page search – this will be coming up in a feature post

Copy and paste the code below into a page template file and replace ‘YOUR TAXONOMY’ with the name of your taxonomy.

As for the array of arguments check out the WordPress codex article.

$list = '';
$groups = array();
$tags = get_terms('YOUR TAXONOMY',$args);
if( $tags && is_array( $tags ) ) {
	foreach( $tags as $tag ) {
		$first_letter = strtoupper( $tag->name[0] );
		$groups[ $first_letter ][] = $tag;
	if( !empty( $groups ) ) {
		foreach( $groups as $letter => $tags ) {
			$list .= "<div><h3>" . $letter . "</h3><ul>";
			foreach( $tags as $tag ) {
				$list .= '<li><a href="/YOUR TAXONOMY/'.$tag->slug.'">'.$tag->name.'</a></li>';
			$list .= '</ul></div>';
		$list .= '';
echo $list;

This code will loop through the terms and create a group for the first character and create the a div with an h3 for the title of the group.

Leave a Reply

Your email address will not be published. Required fields are marked *