0

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>
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
JLR
  • 723
  • 1
  • 8
  • 17
  • 1
    Take a look at that old article: https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – arkascha Oct 30 '22 at 19:00
  • I agree @arkascha. Are you not going to vote to close? – mickmackusa Oct 31 '22 at 02:07
  • Thanks! Charset and collation is set to: utf8mb4_unicode_ci for the database and tables. As I see it, it something else causing the problem? :-) – JLR Oct 31 '22 at 19:21

0 Answers0