AdvancedCustomFields / AdvancedCustomFields/acf

BUG: get_fields function

Open
#867 3 comments 0 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

Hello,

I've discovered a problem with the "get_fields" function. Basically, I use Gutenberg and ACF Pro with Wordplate as a bridge to create blocks via the "acf_register_block_type" function. I also use sage 10 for the theme with Bedrock. But that's just the context, I don't think that's what's causing the bug.

The bug is that when I do get_fields(), for example get_fields(1295), the function returns "false" whereas if I do the same process but with get_field(), for example get_field('duration', 1295), I get the value that is stored in the database "1 day".

I've noticed that by entering the following code :

if (!$field) {
            $field = acf_get_valid_field(
                array(
                    name' => $key,
                    key' => '',
                    type' => '',
                )
            );
        }

line 300 of the api-template.php file, this solved my problem. In fact, in the get_field function, when I can't find my field in the store or in the database, we create a valid field by default using the key passed, whereas in the get_fields function, we don't do this.

Do you have any suggestions? Is it normal for this not to work? Or was it an oversight during development?

Thanks in advance.

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

Start in api-template.php around line 300 and compare the field-resolution paths used by get_fields() and get_field(). Reproduce the reported difference with get_fields(1295) and get_field('duration', 1295), then determine the expected behavior and verify that get_fields() handles the same stored field data consistently.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.