Created
September 28, 2024 19:17
-
-
Save SamuelHadsall/3621a5e5dcf664e321f4be31a2de8c95 to your computer and use it in GitHub Desktop.
Populate list field with php and acf repeater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function populate_company_list_field_with_array($value) { | |
if (current_user_can('employer_admin')) { | |
// Get the current user's company ID | |
$company_id = get_user_meta(get_current_user_id(), 'company_id', true); | |
$list_field_values = array(); | |
// Get the ACF repeater field data | |
$business_locations = get_field('business_locations', $company_id); // Replace with your ACF repeater field name | |
// Check if repeater field has data | |
if ($business_locations) { | |
// Loop through each row in the repeater field | |
foreach ($business_locations as $location) { | |
$list_field_values[] = array( | |
'City' => $location['city'], // Replace 'city' with your ACF subfield name | |
'State' => $location['state'] // Replace 'state' with your ACF subfield name | |
); | |
} | |
} | |
return $list_field_values; | |
} | |
} | |
add_filter( 'gform_field_value_list_21', 'populate_company_list_field_with_array' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment