Support » Plugin: A-Z Listing » Exclude non alphanumeric characters

  • Resolved Török Zoli


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

    “Title” -> should under T not #
    (Post) -> should under P not #

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



    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:

    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 '[':
                // if none of the above match then we use the character as the index
                    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


    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áàäâ,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';


    Thread Starter Török Zoli


    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.