Field Render

Display a Country selector as radio, checkbox or select field type.

Field Group

Field Settings

Setting nameDescription
Allow CountriesFilter which countries can be chosen
AppearanceSelect the appearance of this field
Display FlagDisplay flags next to the country name
Group by ContinentGroup countries by their continent
Display FormatUse specific display format using template tags {localized} {native} {code}
Default ValueEnter each default value on a new line
Return ValueReturn the country array, country name or country 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: Country Name

$countries = get_field('countries');
 
// United States

Return Format: Country Code

$countries = get_field('countries');

// us

Return Format: Country Array

$countries = get_field('countries');

/**
 * array(
 *     'code'       => 'us',
 *     'name'       => 'United States',
 *     'localized'  => 'United States',
 *     'native'     => 'United States',
 *     'dial'       => array(
 *         '1',
 *     ),
 *     'capital'    => 'Washington, D.C.',
 *     'people'     => 'American',
 *     'continent'  => 'America',
 *     'coords'     => array(
 *         'lat' => 38.0,
 *         'lng' => -97.0,
 *     ),
 *     'languages'  => array(
 *         'en_US',
 *     ),
 *     'currencies' => array(
 *         'USD',
 *     ),
 * )
 */

Unformatted Value

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

// us

Custom Query

/**
 * acfe/fields/countries/query
 * 
 * @array        $args     Query arguments
 * @array        $field    Field settings
 * @bool/string  $post_id  Current Post ID
 */
filter('acfe/fields/countries/query',                         $args, $field, $post_id);
filter('acfe/fields/countries/query/name=my_countries',       $args, $field, $post_id);
filter('acfe/fields/countries/query/key=field_5ff50f25a59f6', $args, $field, $post_id);
add_filter('acfe/fields/countries/query/name=my_countries', 'my_acf_countries_query', 10, 3);
function my_acf_countries_query($args, $field, $post_id){
    
    // change orderby & order
    $args['orderby'] = 'name';
    $args['order'] = 'DESC';
    
    // return
    return $args;

}

Custom Result

/**
 * acfe/fields/countries/result
 * 
 * @string       $text     Country result
 * @array        $country  Country object
 * @array        $field    Field settings
 * @bool/string  $post_id  Current Post ID
 */
filter('acfe/fields/countries/result',                         $text, $country, $field, $post_id);
filter('acfe/fields/countries/result/name=my_countries',       $text, $country, $field, $post_id);
filter('acfe/fields/countries/result/key=field_5ff50f25a59f6', $text, $country, $field, $post_id);
add_filter('acfe/fields/countries/result/name=my_countries', 'my_acf_countries_result', 10, 4);
function my_acf_countries_result($text, $country, $field, $post_id){
    
    // change country 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_countries() helper. Here are the default query arguments:

acfe_get_countries(array(
    'code__in'      => false,
    'name__in'      => false,
    'continent__in' => false,
    'language__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 country by code

$country = acfe_get_country('fr');

/**
 * array(
 *     'code'       => 'fr',
 *     'name'       => 'France',
 *     'localized'  => 'France',
 *     'native'     => 'France',
 *     'dial'       => array(
 *         '33',
 *     ),
 *     'capital'    => 'Paris',
 *     'people'     => 'French',
 *     'continent'  => 'Europe',
 *     'coords'     => array(
 *         'lat' => 46.0,
 *         'lng' => 2.0,
 *     ),
 *     'languages'  => array(
 *         'eu',
 *         'fr_FR',
 *         'oci',
 *     ),
 *     'currencies' => array(
 *         'EUR',
 *     ),
 * )
 */

Get multiple countries by code

$countries = acfe_get_countries(array(
    'code__in' => array('us')
));

/**
 * array(
 *     'us' => array(
 *         'code'       => 'us',
 *         'name'       => 'United States',
 *         'localized'  => 'United States',
 *         'native'     => 'United States',
 *         'dial'       => array(
 *             '1',
 *         ),
 *         'capital'    => 'Washington, D.C.',
 *         'people'     => 'American',
 *         'continent'  => 'America',
 *         'coords'     => array(
 *             'lat' => 38.0,
 *             'lng' => -97.0,
 *         ),
 *         'languages'  => array(
 *             'en_US',
 *         ),
 *         'currencies' => array(
 *             'USD',
 *         ),
 *     ),
 * )
 */

Get countries by currency

$countries = acfe_get_countries(array(
    'currency__in' => 'USD',
    'field'        => 'name',
    'limit'        => 3
));

/**
 * array(
 *     'as' => 'American Samoa',
 *     'vg' => 'British Virgin Islands',
 *     'kh' => 'Cambodia',
 * )
 */

Get countries with custom display

$countries = acfe_get_countries(array(
    'code__in' => array('us', 'fr', 'gb'),
    'field'    => 'code',
    'display'  => 'Code: {code} | Country: {name} | Capital: {capital}'
));

/**
 * array(
 *     'fr' => 'Code: fr | Country: France | Capital: Paris',
 *     'gb' => 'Code: gb | Country: United Kingdom | Capital: London',
 *     'us' => 'Code: us | Country: United States | Capital: Washington, D.C.',
 * )
 */