Home › Forums › General Issues › V3 to V4 issue displaying custom field type
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;
}

Hi @the_enn
Thanks for the question.
The function used in v4 is called ‘update_value’. If you take a look at the field type template, you can see the v3 and v4 field types and looking at the comments in the function, you can see the matching functions!
https://github.com/elliotcondon/acf-field-type-template
Cheers
E
The topic ‘V3 to V4 issue displaying custom field type’ is closed to new replies.
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.