Display a Language selector as radio, checkbox or select field type, also compatible with WPML & Polylang.
Setting name | Description |
Allow Languages | Filter which languages can be chosen |
Appearance | Select the appearance of this field |
Display Flag | Display flags next to the language name |
Group by Continent | Group languages by their continent |
WPML/Polylang Languages | Display languages set in WPML or Polylang |
Display Format | Use specific display format using template tags {name} {native} {locale} |
Default Value | Enter each default value on a new line |
Return Value | Return the language array, language name or language locale code |
Allow Null | Allow empty value |
Layout | Choose the layout |
Toggle | Allow to toggle all values |
Allow Custom | Allow custom value |
Save Custom | Save custom value in the field settings |
Select multiple values | Allow multiple values selection |
Stylised UI | Enable Select2 UI style |
$languages = get_field('languages');
// Italian
$languages = get_field('languages');
// it_IT
$languages = get_field('languages');
/**
* array(
* 'code' => 'it',
* 'locale' => 'it_IT',
* 'alt' => 'it_IT',
* 'name' => 'Italian',
* 'native' => 'Italiano',
* 'dir' => 'ltr',
* 'flag' => 'it',
* 'continent' => 'Europe',
* 'countries' => array(
* 'ch',
* 'it',
* 'sm',
* 'va',
* ),
* 'currencies' => array(
* 'CHF',
* 'EUR',
* ),
* )
*/
$languages = get_field('languages', false, false);
// it_IT
/**
* acfe/fields/languages/query
*
* @array $args Query arguments
* @array $field Field settings
* @bool/string $post_id Current Post ID
*/
filter('acfe/fields/languages/query', $args, $field, $post_id);
filter('acfe/fields/languages/query/name=my_languages', $args, $field, $post_id);
filter('acfe/fields/languages/query/key=field_5ff50f25a59f6', $args, $field, $post_id);
add_filter('acfe/fields/languages/query/name=my_languages', 'my_acf_languages_query', 10, 3);
function my_acf_languages_query($args, $field, $post_id){
// change orderby & order
$args['orderby'] = 'name';
$args['order'] = 'DESC';
// return
return $args;
}
/**
* acfe/fields/languages/result
*
* @string $text Language result
* @array $language Language object
* @array $field Field settings
* @bool/string $post_id Current Post ID
*/
filter('acfe/fields/languages/result', $text, $currency, $field, $post_id);
filter('acfe/fields/languages/result/name=my_languages', $text, $currency, $field, $post_id);
filter('acfe/fields/languages/result/key=field_5ff50f25a59f6', $text, $currency, $field, $post_id);
add_filter('acfe/fields/languages/result/name=my_languages', 'my_acf_languages_result', 10, 4);
function my_acf_languages_result($text, $language, $field, $post_id){
// change language result
$text = "<strong>{$text}</strong>";
// return
return $text;
}
It is possible to perform custom PHP queries and retrieve the result using the acfe_get_languages()
helper. Here are the default query arguments:
acfe_get_languages(
'locale__in' => false,
'name__in' => false,
'alt__in' => false,
'code__in' => false,
'continent__in' => false,
'country__in' => false,
'currency__in' => false,
'orderby' => false,
'order' => 'ASC',
'offset' => 0,
'limit' => -1,
'field' => false,
'display' => false,
'prepend' => false,
'append' => false,
'groupby' => false,
);
$language = acfe_get_language('it_IT');
/**
* array(
* 'code' => 'it',
* 'locale' => 'it_IT',
* 'alt' => 'it_IT',
* 'name' => 'Italian',
* 'native' => 'Italiano',
* 'dir' => 'ltr',
* 'flag' => 'it',
* 'continent' => 'Europe',
* 'countries' => array(
* 'ch',
* 'it',
* 'sm',
* 'va',
* ),
* 'currencies' => array(
* 'CHF',
* 'EUR',
* ),
* )
*/
$languages = acfe_get_languages(array(
'locale__in' => array('en_CA')
));
/**
* array(
* 'en_CA' => array(
* 'code' => 'en',
* 'locale' => 'en_CA',
* 'alt' => 'en_US',
* 'name' => 'English',
* 'native' => 'English',
* 'dir' => 'ltr',
* 'flag' => 'ca',
* 'continent' => 'America',
* 'countries' => array(
* 'ca',
* ),
* 'currencies' => array(
* 'CAD',
* ),
* ),
* )
*/
$languages = acfe_get_languages(array(
'currencies__in' => array('CAD'),
'field' => 'name',
'limit' => 3
));
/**
* array(
* 'en_CA' => 'English',
* 'fr_CA' => 'French',
* )
*/
$languages = acfe_get_languages(array(
'locale__in' => array('es_ES', 'fr_FR'),
'field' => 'name',
'display' => 'Name: {name} | Flag: {flag}'
));
/**
* array(
* 'fr_FR' => 'Name: French | Flag: fr',
* 'es_ES' => 'Name: Spanish | Flag: es',
* )
*/