Support

Account

Home Forums General Issues Can't get field objects/update repeater fields for SOME users

Solved

Can't get field objects/update repeater fields for SOME users

  • I’ll try and make this as simple as possible.

    I have repeater fields for every user under “User Role – is equal to – all”.

    When a new user registers, then registration page /wp-login.php?action=register
    shows these fields, even though no user is logged in.It shows them inbetween the submit button and the email box.

    If I add a rule to hide these fields on the registration page such as “User Form – Is Not Equal To – Register”, then the fields don’t show.

    However, if I try to run any php scripts on the new user account which involve repeater fields they do not work.

    For example, the new user’s id is ‘6’:

    $field = get_field_object(‘fieldname’, ‘user_’.’6′);
    echo $field[‘key’];

    Will not show anything. However if I change the user to a user which was created while the fields were showing on the registration form, then it will work.

    For user 6, the bugged user, I can still use update_field etc, but when it comes to repeater fields it all goes dead.

    It feels as though the fields displaying on the registration page somehow initialise the user for these fields and if I don’t show them, then I can’t retrieve or modify the repeaters fields via php scripts.

    The repeater fields still work manually from the profile of the user, but even after updating the profile in wordpress with changes, the repeater fields still do not respond to any php scripts.

    Can you help me understand what the problem is?

  • When using update_field() where a value has not been previously saved you need to use the field key and not the field name. get_field_object() using the field name where a value has not been previously saved will also return no value.

    When you are working with fields, any field type, where a value may not already exist you should always use the field key rather than the field name. This is explained on this page https://www.advancedcustomfields.com/resources/update_field/

  • I have been using the field keys. I sent a support ticket also and they explained that I needed to run this to initalise the field first. update_field('repeater', array(), 'user_'.$user_id);

    Everything seems to be working now.

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

The topic ‘Can't get field objects/update repeater fields for SOME users’ is closed to new replies.