Display a Currency selector as radio, checkbox or select field type.
Setting name | Description |
Allow Currencies | Filter which currencies can be chosen |
Appearance | Select the appearance of this field |
Display Flag | Display flags next to the currency name |
Group by Continent | Group currencies by their continent |
Display Format | Use specific display format using template tags {symbol} {code} {name} |
Default Value | Enter each default value on a new line |
Return Value | Return the currency array, currency name, currency code or currency symbol |
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 |
$currencies = get_field('currencies');
// United States Dollar
$currencies = get_field('currencies');
// USD
$currencies = get_field('currencies');
/**
* array(
* 'code' => 'USD',
* 'name' => 'United States Dollar',
* 'symbol' => '$',
* 'flag' => 'us',
* 'continent' => 'America',
* 'countries' => array(
* 'as',
* 'ec',
* 'fm',
* 'gu',
* 'kh',
* 'mh',
* 'mp',
* 'pa',
* 'pr',
* 'pw',
* 'sv',
* 'tc',
* 'tl',
* 'us',
* 'vg',
* 'vi',
* 'zw',
* ),
* 'languages' => array(
* 'en_US',
* 'es_EC',
* 'es_ES',
* 'es_PR',
* 'km',
* 'pt_PT',
* ),
* )
*/
$currencies = get_field('currencies');
// $
$currencies = get_field('currencies', false, false);
// USD
/**
* acfe/fields/currencies/query
*
* @array $args Query arguments
* @array $field Field settings
* @bool/string $post_id Current Post ID
*/
filter('acfe/fields/currencies/query', $args, $field, $post_id);
filter('acfe/fields/currencies/query/name=my_currencies', $args, $field, $post_id);
filter('acfe/fields/currencies/query/key=field_5ff50f25a59f6', $args, $field, $post_id);
add_filter('acfe/fields/currencies/query/name=my_currencies', 'my_acf_currencies_query', 10, 3);
function my_acf_currencies_query($args, $field, $post_id){
// change orderby & order
$args['orderby'] = 'name';
$args['order'] = 'DESC';
// return
return $args;
}
/**
* acfe/fields/currencies/result
*
* @string $text Currency result
* @array $currency Currency object
* @array $field Field settings
* @bool/string $post_id Current Post ID
*/
filter('acfe/fields/currencies/result', $text, $currency, $field, $post_id);
filter('acfe/fields/currencies/result/name=my_currencies', $text, $currency, $field, $post_id);
filter('acfe/fields/currencies/result/key=field_5ff50f25a59f6', $text, $currency, $field, $post_id);
add_filter('acfe/fields/currencies/result/name=my_currencies', 'my_acf_currencies_result', 10, 4);
function my_acf_currencies_result($text, $currency, $field, $post_id){
// change currency result
$text = "<strong>{$text}</strong>";
// return
return $text;
}
It is possible to perform custom PHP queries and retrieve the result using the acfe_get_currencies()
helper. Here are the default query arguments:
acfe_get_currencies(array(
'code__in' => false,
'name__in' => false,
'continent__in' => false,
'country__in' => false,
'language__in' => false,
'orderby' => false,
'order' => 'ASC',
'offset' => 0,
'limit' => -1,
'field' => false,
'display' => false,
'prepend' => false,
'append' => false,
'groupby' => false,
));
$currency = acfe_get_currency('GBP');
/**
* array(
* 'code' => 'GBP',
* 'name' => 'British pound',
* 'symbol' => '£',
* 'flag' => 'gb',
* 'continent' => 'Europe',
* 'countries' => array(
* 'gb',
* 'im',
* 'je',
* 'zw',
* ),
* 'languages' => array(
* 'cy',
* 'en_GB',
* 'en_US',
* 'fr_FR',
* 'gd',
* ),
* )
*/
$currencies = acfe_get_currencies(array(
'code__in' => array('GBP')
));
/**
* array(
* 'GBP' => array(
* 'code' => 'GBP',
* 'name' => 'British pound',
* 'symbol' => '£',
* 'flag' => 'gb',
* 'continent' => 'Europe',
* 'countries' => array(
* 'gb',
* 'im',
* 'je',
* 'zw',
* ),
* 'languages' => array(
* 'cy',
* 'en_GB',
* 'en_US',
* 'fr_FR',
* 'gd',
* ),
* ),
* )
*/
$currencies = acfe_get_currencies(array(
'languages__in' => 'it_IT',
'field' => 'name',
'limit' => 3
));
/**
* array(
* 'EUR' => 'Euro',
* 'CHF' => 'Swiss franc',
* )
*/
$currencies = acfe_get_currencies(array(
'code__in' => array('USD', 'EUR'),
'field' => 'code',
'display' => 'Code: {code} | Symbol: {symbol} | Flag: {flag}'
));
/**
* array(
* 'EUR' => 'Code: EUR | Symbol: € | Flag: eu',
* 'USD' => 'Code: USD | Symbol: $ | Flag: us',
* )
*/