Support

Account

Home Forums ACF PRO get_field() returning empty array

Solved

get_field() returning empty array

  • 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.

  • Hi @nathangeorge

    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….

  • Hi @nathangeorge

    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….

  • Hi @nathangeorge

    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

  • I had the same issue and upgrading solved it for me.

  • yup, all good now. cheers.

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

You must be logged in to reply to this topic.