Home › Forums › Backend Issues (wp-admin) › [acf/select] missing default value if "stylised UI" is enabled › Reply To: [acf/select] missing default value if "stylised UI" is enabled
Hello
this might be related – I’m trying to populate the default value of a dynamically populated select field – I cannot get it to display the default value – hope somebody can help.
// Populate the category select field with dynamic values
add_filter( 'acf/load_field/name=resource_category', 'prefix_acf_load_resource_category_field' );
function prefix_acf_load_resource_category_field( $field ) {
// reset choices and defaults
$field[ 'choices' ] = array();
$field[ 'default_value' ] = array();
$terms = get_terms( 'resource_category', array( 'hide_empty' => false ) );
foreach ( $terms as $term ) {
$field[ 'choices' ][ $term->slug ] = $term->name;
if ( has_term( $term->slug, 'resource_category', get_the_ID() ) )
$field[ 'default_value' ][] = $term->slug;
}
return $field;
};
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.