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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.