Support

Account

Home Forums General Issues Trouble adding custom choices to a select

Solved

Trouble adding custom choices to a select

  • After many attempts to update choices to a select, I cannot get them to show.

    I have no trouble getting the values into the array:

    Here is my $field array:

    Array
    (
        [ID] => 34249
        [key] => field_58780febd3e05
        [label] => Away Roster
        [name] => away_roster_display
        [prefix] => acf
        [type] => select
        [value] => 
        [menu_order] => 7
        [instructions] => 
        [required] => 0
        [id] => 
        [class] => 
        [conditional_logic] => 0
        [parent] => 11510
        [wrapper] => Array
            (
                [width] => 50
                [class] => 
                [id] => 
            )
    
        [_name] => away_roster_display
        [_prepare] => 0
        [_valid] => 1
        [choices] => Array
            (
                [0] => Bouchard, Kaleb
                [1] => Brown, Alex
                [2] => Coutts, Jackson
                [3] => Dall, Cameron
                [4] => Dana, Jayden
                [5] => Desisto, Nate
                [6] => Farnham, Dylan
                [7] => Henderson, Sam
                [8] => Kenefic, Evan
                [9] => McCluskey, Connor
                [10] => Monk, Jacob
                [11] => Morrison, Jacob
                [12] => Newell, Kaleb
                [13] => Parker, Kohle
                [14] => Pinto, Zac
                [15] => Robertson, Connor
                [16] => Shaw, Dustin
                [17] => Tozer, Matt
                [18] => White, Noah
            )
    
        [default_value] => Array
            (
            )
    
        [allow_null] => 1
        [multiple] => 0
        [ui] => 0
        [ajax] => 0
        [return_format] => value
        [placeholder] => 
    )

    Here is my function. I’ve left out the contents of the array $roster_list:

    function roster_base_z($field){
    $roster_list = array();
    
    $filterByAway = get_field('away_team_2')->post_title;
    $filterByHome = get_field('home_team_2')->post_title;
    
    $field['choices'] = array();
    
    $new = array_filter($roster_list, function ($var) use ($filterByAway) {
        return ($var['school'] == $filterByAway);
    });
    $new1 = array_values($new);
    $new2 = array();
    
    for($i = 0; $i < count($new1); $i++){    
    
            array_push($new2,$new1[$i]['last_name'].", ".$new1[$i]['first_name']);
    
    }
    
    	$field['choices'] = $new2;
    
    	return $field;
    
    }
    
    add_filter('acf/load_field/name=away_roster_display', 'roster_base_z', 20);

    Any help would be appreciated.

  • I figured it out. There were conflicting functions.

  • Hi @bosoxbill ,

    Glad you were able to solve the issue.

    Kindly mark your response as the solution in order to allow the thread to be marked as solved.

    Cheers.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Trouble adding custom choices to a select’ is closed to new replies.