Home › Forums › Backend Issues (wp-admin) › Getting Local Fields at Load_Field filter. › Reply To: Getting Local Fields at Load_Field filter.
Hi John,
Thanks for your response. And you definitly pointed me in the right direction. Using a filter that runs on all fields was the solution I was looking for. I now basically removed the whole filter that had the dynamic part and moved it all to the initialize method. I only had a nesting level issue so I switched to a the ‘afc/prepare_field’ filter instead.
Just for your reference here’s my adjusted code (I only need to do a minor cleanup). And thanks again!
add_filter('acf/prepare_field', function($field) {
$fieldObject = get_field_object($field['key']);
if(!str_starts_with($fieldObject['name'], 'select')){
return $field;
}
$layouts = acf_get_fields('group_5f33b50973315')[0]['layouts'];
$blocks = array_filter($layouts, function($layout){
return in_array('source', array_column($layout['sub_fields'], 'name'));
});
foreach ($blocks as $block) {
if($fieldObject['name'] !== 'select' . ucfirst($block['name'])){
continue;
}
$field['choices'] = [];
$groups = get_field($block['name'], 'options');
foreach($groups as $group){
$field['choices'][$group['groupID']] = $group['name'];
}
}
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.