Hey Elliot,
I noticed a recent update changed the way get_field() works.
In version 5.2.3 if an ACF field was non-existent on a page, get_field() would return NULL.
In version 5.2.5 the return is array ( ” => ”, )
Has caused a heap of issues for me. My only solution was to add the non-existent field to all posts/pages and default the value to false. I’d rather not have to have this ACF field on pages that don’t need it.
Thanks for the bug report.
I’ve just attempted to replicate this, however the returned value is indeed NULL
for get_field('this_field_doesn't_exist');
Perhaps it is possible that a value did exist?
Perhaps it is possible that ACF is applying formatting?
What is the field?
Thanks
E
get_field(‘disable_lead_ins_block’) was my field name.
I thought something like that too. However I had a development instance on 5.2.3 that was returning NULL as expected. Did an update of ACF, refreshed the page and got the empty string array back.
This page/post would never have had this field, and had nothing in the wp_postmeta table.
I’m still digging….
On further investigation, I have found that if I create a select field in the DB with the same name as my get_field
call, the issue occurs!
I’ll compare the 2 versions and have this fixed in the next release
OK I got it.
In version 5.2.5 if there is an ACF field somewhere is the site, EVEN if it doesn’t apply to the page with location rules, it will return that empty string var.
E.g. I had in a template get_field(‘test123’) which returned NULL.
I then created an ACF field called test123 but made the location rules so that it definitely didn’t apply to the page i was testing on.
I refreshed the page and it then returned an empty string var.
Hope this makes sense….
Good news!
I’ve found and fixed the issue.
I’ve just re-uploaded ACF PRO 5.2.6 – please upgrade if possible.
Thanks
E
After upgrading, can you test and report back your findings?
Thanks
E
The topic ‘get_field() returning empty array’ is closed to new replies.
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.