LanguagesPRO

Docs Fields Languages

#Field Render

Display a Language selector as radio, checkbox or select field type, also compatible with WPML & Polylang.

Field Group

#Field Settings

Setting nameDescription
Allow LanguagesFilter which languages can be chosen
AppearanceSelect the appearance of this field
Display FlagDisplay flags next to the language name
Group by ContinentGroup languages by their continent
WPML/Polylang LanguagesDisplay languages set in WPML or Polylang
Display FormatUse specific display format using template tags {name} {native} {locale}
Default ValueEnter each default value on a new line
Return ValueReturn the language array, language name or language locale code
Allow NullAllow empty value
LayoutChoose the layout
ToggleAllow to toggle all values
Allow Custom
Allow custom value
Save Custom
Save custom value in the field settings
Select multiple valuesAllow multiple values selection
Stylised UIEnable Select2 UI style

#Field Value

#Return Format: Language Name

$languages = get_field('languages');

// Italian

#Return Format: Language Locale Code

$languages = get_field('languages');

// it_IT

#Return Format: Language Array

$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',
 *     ),
 * )
 */

#Unformatted Value

$languages = get_field('languages', false, false);

// it_IT

#Custom Query

/**
 * 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;

}

#Custom Result

/**
 * 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;

}

#PHP Query

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,
);

#Get single language by locale code

$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',
 *     ),
 * )
 */

#Get multiple languages by code

$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',
 *         ),
 *     ),
 * )
 */

#Get languages by currency

$languages = acfe_get_languages(array(
    'currencies__in' => array('CAD'),
    'field'          => 'name',
    'limit'          => 3
));

/**
 * array(
 *     'en_CA' => 'English',
 *     'fr_CA' => 'French',
 * )
 */

#Get languages with custom display

$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',
 * )
 */