Skip to content

Instantly share code, notes, and snippets.

@tdrayson
Created August 23, 2022 09:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tdrayson/05e2c951a57bb18eb63b51e9d4f89f9b to your computer and use it in GitHub Desktop.
Save tdrayson/05e2c951a57bb18eb63b51e9d4f89f9b to your computer and use it in GitHub Desktop.
Populate ACF dropdown with Fluent forms
<?php
/*
Instructions
Replace YOUR_ACF_FIELD with the name of your acf select dropdown key
Add to functions.php or code snippets plugin
Forms will load sorted by Title in ASC order (A to Z)
Label = Form Title
Value = Form ID
*/
if ( !function_exists('tct_select_fluent_form') ):
add_filter('acf/load_field/name=YOUR_ACF_FIELD', 'tct_select_fluent_form');
function tct_select_fluent_form( $field ){
// reset choices
$field['choices'] = array();
$formApi = fluentFormApi('forms');
$atts = [
'status' => 'all',
'sort_column' => 'title',
'sort_by' => 'ASC',
'per_page' => 500,
];
$forms = $formApi->forms($atts, $withFields = false);
foreach($forms['data'] as $form){
$field['choices'][ $form->id ] = $form->title;
};
return $field;
}
endif;
/*
Sources:
https://www.scratchcode.io/dynamically-populate-a-select-fields-choices-in-acf/
https://fluentforms.com/docs/fluent-form-php-api/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment