Support

Account

Home Forums Bug Reports Problems manually updating a repeater field via code on a newly inserted post Reply To: Problems manually updating a repeater field via code on a newly inserted post

  • Ok, I too fixed my own problem, but the bug is traced to something in the ACF documention (https://www.advancedcustomfields.com/resources/register-fields-via-php/ see “Add within an action“)

    So the issue is that if you are registering your ACF fields via php (which is very good for multi-sites with shared ACF fields), there is a case (and a darn rare one), in which get_field is being called before the action has ran its course, which leads the acf local fields array to only be partially populated. Therefore acf_get_local_field($key) returns false, and instead of returning the complex object, it just returns the value at the key index in the DB, which for a repeater, returns the number of items in said repeater.

    TL;DR;

    If you are enqueuing your ACF fields in an action (and exhibiting this bug), don’t add them to ‘acf/init’, add them to regular ‘init’, and then the local_field array is populated before any instance of get_field is called.

    ACF peeps? Can you please fix child theme calls to get_field, in which the parent theme is registering acf fields (on ‘acf/init’) or change your documentation to tell people to call their php includes of acf fields at wordpress’s ‘init’?