0
votes

So what I want to do is set a radio button to selected from the backend in functions.php. I have a ACF field with two options - 'blue' which is selected by default and 'red' which is unselected

So I've got this function in functions.php and I'm trying to update the choices array but I'm not having much luck ...

I can reset all the choices set in my array etc so I know I've got the right field etc and close to getting this but I'm missing that last piece of the puzzle

function acf_load_colours_field_choices( $field ) {

if( is_array($choices) ) {

    foreach( $choices as $choice ) {
        $field['choices'][ $choice ] = $choice;
        update_field('field_1234567890', checked );
    }

}

return $field;

}

add_filter('acf/load_field/name=user_level', 'acf_load_colours_field_choices');

So what I've tried to do is update the field 'field_1234567890' and set it as checked but that isn't working and I'm not sure how else to do it ... I've gone off the fields key but happy to go off value etc if that makes more sense

If someone can point me in the right direction on this one I'd be hugely grateful!

1

1 Answers

0
votes

Sorry if I'm point out the obvious, but you can set default select in the ACF set up for your radio / select fields. It's a drop down which is available.

That's my recommendation!