• ceol

    (@ceol)


    Hi.
    Trying to implement solution from here:

    <?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;
    }

    by inserting into child theme functions.php but getting errors.
    Any advice for a tech knuckle-head most appreciated.
    Many thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter ceol

    (@ceol)

    …inserted comma in first line before 10 like so:
    add_filter( 'a_z_listing_item_index_letter', 'ignore_quotes_in_a_z', 10, 3 );
    Saves ok now but doesn’t appear have any effect on the listing.
    Any ideas much appreciated,
    Thanks

    • This reply was modified 5 years ago by ceol.
    Thread Starter ceol

    (@ceol)

    Have several instances (one per category) in a page using shortcode like: [a-z-listing display="posts" post-type="post" taxonomy="category" terms="miscellaneous" grouping="26" if that’s relevant. thanks

    • This reply was modified 5 years ago by ceol.
    • This reply was modified 5 years ago by ceol.
    Plugin Author Dani Llewellyn

    (@diddledani)

    Hi,

    Can you post an example of a title that is failing to ignore a special character with the above code?

    Make sure you copy it from the title field in your wp-admin editor and paste it inside a “code” block here, so that any special characters are not mangled by any intermediate processes. To paste into a code block click the “code” item in the toolbar above the reply text box and then paste the title between the ` characters.

    Thread Starter ceol

    (@ceol)

    Hi.
    'a test apostrophe index title'
    "a test quote index title"
    Thanks for replying.

    Plugin Author Dani Llewellyn

    (@diddledani)

    Oh, I think I see the issue.

    You’ve set grouping=26 which will group all the posts into a single bucket. This means that the only ordering will be via a PHP comparator using strcmp. The above code will only affect which group a particular title is listed within, not its order inside that group.

    Thread Starter ceol

    (@ceol)

    Hi.
    I removed the grouping just to see but no change; very strange.
    Thanks

    Thread Starter ceol

    (@ceol)

    Hi.
    I’ve discovered that part of the issue seems to be with certain characters only: seems to be working with ( and [, but not with or \
    How might I get it working for double quotes and apostrophe?
    Thanks

    Plugin Author Dani Llewellyn

    (@diddledani)

    I suspect the issue with double-quotes or apostrophe might be a difference between " and or ' and .

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