Support

Account

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;
            }
        }
    }