Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created March 13, 2014 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/42432c1840d29d9fb3c2 to your computer and use it in GitHub Desktop.
Save tommcfarlin/42432c1840d29d9fb3c2 to your computer and use it in GitHub Desktop.
[WordPress] How to define a new locale for sorting data.
<?php
// Set a new locale, define string comparison functions to be affected,
// and store the original locale.
$original_locale = setlocale( LC_COLLATE, 'de_DE' );
// Do whatever you need to do for German sorting here
// Reset the locale to its original state
setlocale( LC_COLLATE, $original_locale );
<?php
// Instantiate the Collator and pass it the locale
$col = new \Collator( 'de_DE' );
// Sort the array of last names.
$col->asort( $last_names )
// Done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment