Display a Country selector as radio, checkbox or select field type.
Setting name | Description |
Allow Countries | Filter which countries can be chosen |
Appearance | Select the appearance of this field |
Display Flag | Display flags next to the country name |
Group by Continent | Group countries by their continent |
Display Format | Use specific display format using template tags {localized} {native} {code} |
Default Value | Enter each default value on a new line |
Return Value | Return the country array, country name or country 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 |
Value can then be retrieved using the common get_field()
function. Usage example:
$slug = get_field('countries');
// france
It is possible the perform custom queries and retrieve the result in PHP 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,
));
Usage examples:
$countries = acfe_get_countries(array(
'code__in' => 'us'
));
/*
* Array(
* [us] => Array(
* [code] => us
* [name] => United States
* [localized] => United States
* [native] => United States
* [dial] => Array(
* [0] => 1
* )
* [capital] => Washington, D.C.
* [people] => American
* [continent] => America
* [coords] => Array(
* [lat] => 38
* [lng] => -97
* )
* [languages] => Array(
* [0] => en_US
* )
* [currencies] => Array(
* [0] => USD
* )
* )
* )
*/
$countries = acfe_get_countries(array(
'currency__in' => 'USD',
'field' => 'name',
'limit' => 3
));
/*
* Array(
* [as] => American Samoa
* [vg] => British Virgin Islands
* [kh] => Cambodia
* )
*/
$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.
* )
*/