Support

Account

Home Forums General Issues Multiple Select User Field and update_field() Reply To: Multiple Select User Field and update_field()

  • I just have a quick follow-up question to this original question, and didn’t want to clutter the forum with additional posts. If I should make an additional post, please let me know.

    So everything is working perfectly fine up until this point. I am able to add and remove Users as I please, so long as the User Field is initially populated in the Post.

    However, when using a Multiple Select User Field, if no User is initially populated in the Post, and the following command is run:

    $test = get_field('cb_roster', false, false);
    print_r($test);

    This returns nothing at all. Therefore, if I use something like:
    array_push($test, $current_user);

    Nothing will happen (since it doesn’t exist).

    So, if I run the following:

    $current_user = get_current_user_id();
    $current_user = strval($current_user); //converting to string just in case
    
    $test = get_field('cb_roster', false, false);
    $current_user = array($current_user);
    print_r($test);
    print_r($current_user);
    
    update_field('cb_roster', $current_user);

    And then run:

    $test = get_field('cb_roster', false, false);
    print_r($test);

    I get a blank value (as though it does not exist).

    The output for print_r($current_user) returns:
    Array ( [0] => 24 )

    Which matches the format of the Array if it were populated from the Post.

    Any input is greatly appreciated!