Support

Account

Home Forums Backend Issues (wp-admin) Populate select color from option to a page Reply To: Populate select color from option to a page

  • This was one of my functions that loaded values into a select drop down.

    function acf_load_vodka_drink_repeater_field_choices ( $field ) {

    // reset choices
    $field[‘choices’] = array();

    // if has rows
    if( have_rows(‘vodka_master_list’, ‘option’) ) {

    // while has rows
    while( have_rows(‘vodka_master_list’, ‘option’) ) {

    // instantiate row
    the_row();

    // vars
    $title = get_sub_field(‘drink_name’);
    $label = get_sub_field(‘drink_name’);
    $description = get_sub_field(‘description’);
    $alcohol = get_sub_field(‘alcohol_%’);
    $poundsign = ‘£’;

    if( have_rows(‘per_pub_group_pricing’) ) {

    // while has rows
    while( have_rows(‘per_pub_group_pricing’) ) {

    // instantiate row
    the_row();

    // vars
    $id = get_sub_field(‘pub’);
    $small = get_sub_field(’25ml’);
    $medium = get_sub_field(’50ml’);

    //start of if statements

    if (is_page( $id )) {

    if(!empty($small)){
    $drinksizeonewithicon = $poundsign . $small;
    }
    if(!empty($medium)){
    $drinksizetwowithicon = $poundsign . $medium;
    }

    }

    }
    }

    $value = ‘<div class=”titlediv”><h2>’ . $title . ‘</h2></div><div class=”pricediv boxespriceddiv”><div class=”individualprice”><b>’ . $drinksizetwowithicon. ‘</b></div><div class=”individualprice”><b>’ . $drinksizeonewithicon . ‘</b></div><div class=”individualprice”><b></b></div><div class=”individualprice”><b>’ . $alcohol . ‘%</b></div></div><div class=”descriptionclass”><p>’ . $description . ‘</p></div>’;
    // append to choices
    $field[‘choices’][$value] = $label;

    }

    }

    // return the field
    return $field;

    }

    add_filter(‘acf/load_field/key=field_5db8696c5e753’, ‘acf_load_vodka_drink_repeater_field_choices’);

    copy and paste it into your code editor, have a read, could help you out.