Support

Account

Home Forums General Issues Pre-populating drop-down choices

Solved

Pre-populating drop-down choices

  • I have a custom dropdown field that I would like to pre-populate within options from the admin Customizer, I am using the Kirki Toolkit to create the options in the Customizer adding them into a single textarea field/variable each option separated by a comma like;

    option_1,option_2,option_3

    I then have access to this as a single variable, how can I use this to populate a custom field, I have seen this article

    https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

    but it is in reference to the options page created by ACF, so I am not sure how to add for example choice_1 as;

    choice1 => Choice 1

    Any help is greatly appreciated.

  • It would work the same say, but you’ll need to convert the value returned from the other plugins textarea to an array of choices. This is a basic example of the code you’d use in the load field filter:

    
    $values = get_value_from_kirki_toolkit(); // get the text value
    $values = explode(',', $values); // split the string into an array
    $values = array_map('trim', $values); // trim all the values
    foreach ($values as $value) {
      $field['choices'][$value] = $value;
    }
    return $field;
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.