## Populate field choices with wp_insert_post

Question

I have a function which is called when I insert a new post.
Inside this function I have an array with some data. I have also registered a acf select field.

I am trying to update the acf field’s choices with the values from my array. It seems to update the field but it doesn’t shown up on the field in the admin area.

My code is this:

function xml_data(){
$data_array; //my array with my data$field = get_field_object('field_1');
$field['choices'] = array(); foreach($$data_array as$choice){
$field['choices'][$choice ] = \$choice;
}
}



and also:

if( function_exists('acf_add_local_field_group') ):

'key' => 'group_1',
'title' => 'My Group',
'fields' => array (
array (
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => 'select',
'choices' => array(

)
)
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
));

endif;


All of the aboves are in my functions.php file.
Can anyone help please? Thank you

0
5 months 2020-12-29T09:10:24-05:00 0 Answers 5 views 0