Home › Forums › Backend Issues (wp-admin) › Dropdown value saved but not loaded back › Reply To: Dropdown value saved but not loaded back
Hi @tazintosh
I’m not sure how you get the $databaseValue
variable, but I believe you need to get the database value by using the get_field()
function instead. For a single select field, you should be able to do it like this:
function my_acf_load_database_value($field){
// get the current post
global $post;
// get the database value
$db_value = get_field($field['name'], $post->ID, false);
//set the choices
$field['choices'][$db_value] = $db_value;
return $field;
}
add_filter('acf/load_field/key=' . $imageSizeSelect, 'my_acf_load_field', 20, 1);
But is seems you are using the repeater field to contain the select fields. In this case, you can try the following code:
function my_acf_load_database_value($field){
// get the current post
global $post;
// get the database value
$db_value = get_field('repeater_field_name', $post->ID, false);
// loop through the repeater value
foreach( $db_value as $row ){
// get the current row value
$row_select_value = $row[$field['key']];
// set the choices
$field['choices'][$row_select_value] = $row_select_value;
}
// return
return $field;
}
add_filter('acf/load_field/key=' . $imageSizeSelect, 'my_acf_load_field', 20, 1);
If that doesn’t work, could you please share the JSON export file of your field group so I can test it out on my installation?
Thanks 🙂
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.