Glossary layout – create indexes from second word (last name, surname)

Content Views Pro helps you to show posts in glossary layout easily (see demo).
If your post’s title is person name, you might want to list people by their surname (last name). To do that, please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

// Content Views Pro - Glossary index by last name (surname)
add_filter( 'pt_cv_glossary_key', 'cvp_theme_glossary_key_change', 100, 2 );
function cvp_theme_glossary_key_change( $args, $title ) {
	global $pt_cv_id;
	if ( $pt_cv_id === 'VIEW_ID' ) {
		$next_word	 = mb_substr( $title, (int) strpos( $title, ' ' ) + 1 );
		$args		 = mb_substr( $next_word, 0, 1 );
	}

	return $args;
}

(replace VIEW_ID with ID of your View)

Best regards,

Scroll to Top