Home Forums General Issues Select field not returning array as expected


Select field not returning array as expected

  • I define my ACF fields in PHP, and I have a few select boxes. I have set the return value for each to array, yet I only get the label. I also get the label if I set the return value to value.

    Here is my field definition:

    ‘key’ => ‘field_historical_person_details_sex’,
    ‘label’ => ‘Sex’,
    ‘name’ => ‘sex’,
    ‘type’ => ‘select’,
    ‘choices’ => [
    ‘male’ => ‘Male’,
    ‘female’ => ‘Female’,
    ‘return_format’ => ‘array’,

    In this case, when I dump everything for this post I get:

    'sex' => string 'male' (length=4)

    I made sure I deleted and recreated the post after changing the ACF field settings just in case that mattered, and it made no difference.

    Update: It appears that I get arrays for select fields inside repeater fields. :confused:

  • I solved this, and it was actually my misunderstanding of how Timber works.

    I was getting the field value like this: post.field, whereas I should have been using the get_field method: post.get_field('field').

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

The topic ‘Select field not returning array as expected’ is closed to new replies.