Support

Account

Home Forums General Issues Create, Define, Add,Update fields in WP User Profiles

Solved

Create, Define, Add,Update fields in WP User Profiles

  • Hi guys

    I’ve been coding a fake betting site and your plugin has been a massive part of that.

    However I’ve run across a problem and I don’t know how to fix it.

    I use many fields in the user profiles but for this example, we can just look at the bank balance of each user which is a simple number field.

    I have created the field for bank balance and added its location to user profiles. However, that bank balance does not exist until a user manually presses “Update” on their profile.

    Is there a way that I can define and create all of the bank balances for every user?

    Would adding an account creation script that defines the variable/field when a user registers be possible and the correct way to do it?

    I’m using ACF version 4. Do I need to upgrade to do this?

    *Edit*

    I’ve realised I can use either of these:

    <?php  update_field( 'testbankbalance',"15",'user_'.$user_id); ?>
    <?php update_usermeta( $user_id, 'testbankbalance', "11" ); ?>

    This successfully alters the value in a field in the user profile of the selected user.

    However, I need to do this for a repeater field. Is it possible to do this using the update metadata method? Right now my repeater fields show no rows when I try to loop through them. I need to define the repeater fields for every user.

  • you can use update_field() to set the value. Pass an array for the values

    
    array(
      // nested array for each row
      array(
        // element for each field
        'field_409832048038' => 'value',
        'field_04230949393a' => 'value',
        // etc
      )
    )
    

    I show field keys because it’s better to use field keys when updating fields that may not have values yet.

  • I upgraded to Pro version which gave me the ability to alter repeater array sizes. I am using a work around for now.

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

The topic ‘Create, Define, Add,Update fields in WP User Profiles’ is closed to new replies.