AdvancedCustomFields / AdvancedCustomFields/acf

Repeater field returning false instead of [] when empty

Open
#701 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

This is an excerpt of one of our acf-json files:

{
  "key": "field_1111,
  "label": "Filters",
  "name": "filters",
  "type": "repeater",
  "sub_fields": [
    {
      "key": "field_2222",
      "label": "Key",
      "name": "key",
      "type": "select",
      "choices": {
        "foo": "Foo",
        "bar": "Bar"
      },
      "default_value": [], // <-- this changed to false after ACF Pro update from 5.8.7 to 5.12.3
      "allow_null": 0,
      "multiple": 0,
      "return_format": "value",
    }
  ]
}

And sure, this makes sense. The sub_field "key" is a single select so it should return false when nothing is selected. In case of multiple select, an empty array makes more sense.

But: In case the parent repeater field "filters" is empty (= no items inside the repeater) ACF Pro will return false for this field. Expectation should still be an empty array for an empty repeater. Right?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the provided ACF JSON configuration, comparing ACF Pro 5.8.7 and 5.12.3 when the filters repeater has no items. Verify that an empty repeater returns [] while an empty single-select sub-field still returns false.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.