I need to divide a set of taxonomy terms by the first letter of the term name. I found a few bits of code that may help but when I implement my code I get no return values. I'm sure it has to be something fairly small in my code but I just cannot find it.
This taxonomy contains brands and labels carried by shops listed on my site. So the number of terms is quite large. Some of the labels/brands/terms start with numbers, other letters and others are foreign characters like Russian and could be Japanese, Arabic etc as the site grows
The following code is just my first run to show only the terms that begin with Letters.
$letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $numbers = array(0,1,2,3,4,5,6,7,8,9); $chracters = array_merge( $letters, $numbers ); $args = array( 'orderby' => 'name', 'order' => 'asc' ); $terms = get_terms( $taxonomy, $args ); if( count($terms) > 0 ): foreach( $terms as $term ): $firstchar = (string) substr( $term->name, 0 ); $firstchar = strtoupper( $firstchar ); $termlink = get_term_link( $term->slug, $taxonomy ); if( in_array($firstchar,$letters) ): ?> <div class="post-box alignleft"> <p class="post-title"><a href="<?php echo $termlink; ?>"><?php echo $term->name; ?></a></p> </div> <!-- /end .post-box --> <?php endif;//is a letter endforeach;//$terms as $term endif;//count>0
I am not sure what is causing terms not to display. Here is the link to the development server http://obeliskwebdesign.com/sandbox/directorysexy/in-stock-sort/
Thanx for any insights or help. I've been stumped.