I have a WordPress-site where I'm trying to list categories from an specific taxonomy and sort them by letter from A-Z and other letters like swedish Å, Ä and Ö.
The problem is that characters like Å, Ä and Ö is not displayed.
If I do like this I can see the letters:
print_r($term_list[utf8_decode($letter)]);
it seems like there is an encoding issue? Or? The letters "ÅÄÖ" is found under letter "Ã" if I add utf8_decode().
I could need some help here to understand what the problem is an how to solve it.
<?php
$alphabet = array("1","7","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","Å","Ä","Ö","Ã","Î");
$args = array(
'taxonomy' => 'bryggeri',
'orderby' => 'name',
'order' => 'ASC',
);
$cats = get_categories($args);
$term_list = [];
foreach ( $cats as $cat ){
$first_letter = $cat->name[0];
$term_list[$first_letter][] = $cat;
}
unset($cat);
?>
<div class="tag-list">
<?php
foreach ( $alphabet as $letter) : ?>
<div class="term-row" id="<?php echo $letter; ?>">
<div class="term-letter">
<h3><?php echo $letter;?></h3>
</div>
<div class="tag-items">
<?php
// print_r($term_list); <-- Displays Å Ä Ö
// print_r($letter); <-- Displays Å Ä Ö
// print_r($term_list[$letter]); <-- Do not display Å Ä Ö
if (empty($term_list[$letter])): ?>
<div class="tag-item">
<p>-</p>
</div>
<?php else:
foreach ( $term_list[$letter] as $term ):
$count = $term->count;
?>
<div class="tag-item">
<a href="<?php echo get_term_link( $term );?>"><?php echo $term->name;?></a> (<?php echo $count; ?>)
</div>
<?php endforeach;?>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>