I’m migrating from v3 to v4. I’ve successfully converted the functions as described in the migration guide. And when I go to Custom Fields, my field type appears in the drop down (it’s a choice of checkboxes) with its values, e.g.:
1 : MA
2 : CT
3 : RI
However, my problem is that when this custom field type is displayed (on a certain page type in the dashboard) I get this message:
No choices to choose from
I’m wondering if this has something to do with the fact that I am confused on where to convert the v3 ‘pre_save_field’ function to v4 mechanics. The readme.txt says pre_save_field has been converted to acf_save_field hooks, but I don’t see anything in the docs about acf_save_field.
Would this have anything to do with the error message? If so, could someone point me in the right direction on how/where to convert v3 pre_save_field?
Thanks. If it’s helpful here is the v3 pre_save_field function.
function pre_save_field($field)
{
// defaults
$field['choices'] = isset($field['choices']) ? $field['choices'] : '';
// vars
$new_choices = array();
// explode choices from each line
if(strpos($field['choices'], "\n") !== false)
{
// found multiple lines, explode it
$field['choices'] = explode("\n", $field['choices']);
}
else
{
// no multiple lines!
$field['choices'] = array($field['choices']);
}
// key => value
foreach($field['choices'] as $choice)
{
if(strpos($choice, ' : ') !== false)
{
$choice = explode(' : ', $choice);
$new_choices[trim($choice[0])] = trim($choice[1]);
}
else
{
$new_choices[trim($choice)] = trim($choice);
}
}
// update choices
$field['choices'] = $new_choices;
// return updated field
return $field;
}