I’m trying to set the default value of a textbox to a WordPress option I’m setting in another page
The code I have is as follows, can anyone tell me what I’m doing wrong as the default value does not get set
function my_acf_load_field( $field )
{
$field = get_option('global_apr');
return $field;
}
// acf/load_field/key={$field_key} - filter for a specific field based on it's name
add_filter('acf/load_field/key=field_86', 'my_acf_load_field');
Hi @chrisallen76
perhaps instead of overriding the entire field, you want to update the default value?
$field['default_value'] = get_option('global_apr');
Thanks
E
That’s exactly what I want to do, however the text box does not populate t all
I’ve checked the field key and the get_option variable and both are correct
here is my current code, am I missing something?
function my_acf_load_field( $field )
{
$field['default_value'] = get_option('global_apr');
return $field;
}
add_filter('acf/load_field/key=field_86', 'my_acf_load_field');
Hi @chrisallen76
Can you check that the filter is running by changing your function code to:
<?php
$field['default_value'] = get_option('global_apr');
echo '<pre>';
print_r( $field );
echo '</pre>';
die;
return $field;
?>
Does the print_r / die produce any visible results on a page load?
Thanks
E