Home › Forums › Feature Requests › Update_field to automatically use field key › Reply To: Update_field to automatically use field key
Here’s a function which grabs the field key from registered field groups given a name (note it returns the first key found, so it won’t work with multiple fields with the same name):
function get_acf_field_key($name) {
if( !empty($GLOBALS['acf_register_field_group']) ) {
foreach( $GLOBALS['acf_register_field_group'] as $acf ) {
foreach($acf['fields'] as $field) :
if ( $name === $field['name'] ) {
return $field['key'];
}
endforeach;
}
}
}
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.