Home › Forums › ACF PRO › Update Default Value of Field Object › Reply To: Update Default Value of Field Object
I managed to do it by using the method below, but would like to know if there is a better way to do this.
function acf_load_red_color($field) {
$field['default_value'] = '#EA2830';
return $field;
}
function acf_load_green_color($field) {
$field['default_value'] = '#219BA6';
return $field;
}
function acf_load_blue_color($field) {
$field['default_value'] = '#000000';
return $field;
}
$style = get_field('base_style', 'option');
if($style == 'red') {
add_filter( 'acf/load_field/key=field_53bd8ce3bfc22', 'acf_load_red_color' );
add_filter( 'acf/load_field/key=field_53bbfc499145f', 'acf_load_red_color' );
} elseif ($style == 'green') {
add_filter( 'acf/load_field/key=field_53bd8ce3bfc22', 'acf_load_green_color' );
add_filter( 'acf/load_field/key=field_53bbfc499145f', 'acf_load_green_color' );
} elseif ($style == 'blue') {
add_filter( 'acf/load_field/key=field_53bd8ce3bfc22', 'acf_load_blue_color' );
add_filter( 'acf/load_field/key=field_53bbfc499145f', 'acf_load_blue_color' );
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.