Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter elroyski

    (@elroyski)

    Works 🙂 Thank you for your help!

    Thread Starter elroyski

    (@elroyski)

    Many thanks! Great plugin 🙂

    Just one more thing, Daniel 🙂 These pages under the # sign.
    How to fix it? I created a custom alphabet, but this not resolve problem.

    (Ł,Ć,Ö in surname)

    #
    Jacek Łukawski
    Jakub Ćwiek
    Mesut Özil
    Tomasz Łapiński

    Thread Starter elroyski

    (@elroyski)

    Thank you Daniel for the answer. After adding the code, I get many error

    Warning: Invalid argument supplied for foreach() in /usr/home/public_html/wp-content/plugins/a-z-listing/src/Indices.php on line 106

    Thread Starter elroyski

    (@elroyski)

    My code:

    add_filter( 'a_z_listing_item_indices', 'my_a_z_index_filter', 10, 3 );
    
    function my_a_z_index_filter( $indices, $item, $item_type ) {
        // make sure we're filtering the right post type
        if ( 'page' === get_post_type( $item ) ) {
            // pull the title and get the first letter of the second word
            $full_name = explode( ' ', $item->post_title );
    
            // the last word is in the last element of $title_parts so check it is there
            $last_name = array_pop( $full_name );
    
            // ensure we actually found a last name
            if ( $last_name )  {
                // cut the first letter out for our index
                $index = substr( $last_name, 0, 1 );
    
                // set up a new empty array
                $indices = array();
    
                // only the first names are left in $full_name. Join them together again
                $first_names = join( ' ', $full_name );
    
                // Now put the last name first and separate with a comma+space from the first names
                $formatted_name = "{$first_names} {$last_name}";
    
                // add the new name associated with the item into the new array we created
                $indices[ $index ][] = array(
                    'title' => $formatted_name,
                    'item' => $item,
                );
    
                // return a new array with our new index letter instead of the
                // indices already discovered by the plugin
                return $indices;
            }
        }
    
        // if we get here we didn't override the indices so return
        // those already discovered.
        return $indices;
    }
    
    
Viewing 4 replies - 1 through 4 (of 4 total)