Support

Account

Home Forums Add-ons Repeater Field get_field() for repeater returning string instead of array Reply To: get_field() for repeater returning string instead of array

  • Incase it’s useful to anyone looking. I troubleshooted this issue down to a specific behavior in my project.

    The bug
    In a plugin I was authoring, I called get_field on repeater too early which caused a whole host of problems with ACF including the repeater field returning only it’s count as a string, and data seemingly not saving to the repeater when pressing the Update button.
    (in reality, ACF was saving the edits properly to the database but displaying an empty repeater in the post editor as a result of this error).

    The solution was to hook my ACF-dependent logic to the acf/init action instead found here:
    https://www.advancedcustomfields.com/resources/acf-init/

    Without hooking into acf/init, you would expect PHP to throw a fatal error and say get_field() is not a function in this case, but that didn’t happen.

    I’m thinking get_field() was being called in some intermediary matter– after the get_field() function was registered, but before other functions in its call stack were available– resulting in a half-baked instantiation for that particular repeater’s data.

    ¯\_(ツ)_/¯.