• Resolved T?r?k Zoli

    (@torokzoli)


    Is it possible to exclude non alphanumeric characters from sorting and search the next alphanumeric letter instead?

    e.g.
    “Title” -> should under T not #
    (Post) -> should under P not #
    etc

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Dani Llewellyn

    (@diddledani)

    Hi,

    Each item in the list is passed through a filter called a_z_listing_item_index_letter which allows you to change the detected index letter. For this example you can do something like below:

    <?php
    add_filter( 'a_z_listing_item_index_letter', 'ignore_quotes_in_a_z' 10, 3 );
    function ignore_quotes_in_a_z( $indices, $item, $item_type ) {
        $title = get_the_title( $item );
        for ( $i = 0; $i < strlen( $title ); $i++ ) {
            $letter = substr( $title, $i, 1 );
            switch ( $letter ) {
                // add all the characters you want to ignore here - switch falls-through
                // so if any one of these are matched we hit the break; and continue
                // to the next letter in the title.
                case '"':
                case '\'':
                case '(':
                case '[':
                    break;
                // if none of the above match then we use the character as the index
                default:
                    return [ $letter ];
            }
        }
    
        // This is here to handle the case of the above code not giving an index
        return $indices;
    }
    Thread Starter T?r?k Zoli

    (@torokzoli)

    Hi there,

    Thanks for the answer.

    It works, but not as expected, all accented characters (ááééííóó????úúüü??) went under #

    I added some characters to the alphabet with the following code, it worked fine until now.

    add_filter( 'a-z-listing-alphabet', 'add_hun');
    function add_hun( $alphabet ) {
      return 'Aáà??aáà?a,Bb,C?c?,Dd,Eéè?êeéè?ê,Ff,Gg,Hh,Iíì??iíì??,Jj,Kk,Ll,Mm,Nn,Oóò???oóò???,Pp,Qq,Rr,Ss?,Tt,Uúùü??uúùü??,Vv,Ww,Xx,Yy,Zz';
    }

    Thanks

    Thread Starter T?r?k Zoli

    (@torokzoli)

    with mb_substr() instead of substr() works great, thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude non alphanumeric characters’ is closed to new replies.