Home › Forums › Front-end Issues › Pre-Populate GF form with ACF Field Data › Reply To: Pre-Populate GF form with ACF Field Data
If all of your fields in GF have the same field name as the field names in ACF then there is a way that you can use a single function, that’s if I’m understanding the GF hook from what I’m seeing.
I’m assuming that the GF hook is "gform_field_value_{$your_field_name}"
Lets say you have 2 fields
$field_names = array('field_1', 'field_2');
foreach ($field_names as $name) {
add_filter('gform_field_value_'.$name, 'load_my_custom_values');
}
function load_my_custom_values($value) {
// get the current filter that was called
// it will contain the field name
$filter = current_filter();
// remove 'gform_field_value_' from filter name
$field = str_replace('gform_field_value_', '', $filter);
$id = get_current_user_id();
$post_id = 'user_'.$id;
$value = get_field($field, $post_id);
return $value;
}
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.