Skip to content

Instantly share code, notes, and snippets.

@tdrayson
Created August 23, 2022 09:54
Show Gist options
  • Save tdrayson/05e2c951a57bb18eb63b51e9d4f89f9b to your computer and use it in GitHub Desktop.
Save tdrayson/05e2c951a57bb18eb63b51e9d4f89f9b to your computer and use it in GitHub Desktop.

Revisions

  1. tdrayson created this gist Aug 23, 2022.
    46 changes: 46 additions & 0 deletions populate-dropdown.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    <?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/
    */