Support

Account

Home Forums Add-ons Repeater Field Update_field for user field

Solved

Update_field for user field

  • I have a question and i can’t seem to find any related problems. I am trying to set a user inside a user field, this user field is inside of a repeater. What does the user field require to update the field? Currently i hardcoded this example:

    
    update_sub_field( array('related_player', 1, 'reservation_participant'), 'user_3',  204);
    

    Where related_player is my repeater field name and reservation_participant is my sub_field name.

    Any help would be appreciated.

  • Does the repeater and sub field already exist as a value in the database or are you setting a value for a field that has never been set before?

  • I do see that the fields are being set in the wp_postmeta and also the value is set see this image:

  • I think you have the value and post ID arguments backwards

    https://www.advancedcustomfields.com/resources/update_sub_field/

    This is what you have

    
    update_sub_field(
      array('related_player', 1, 'reservation_participant'), // selector
      'user_3', // value
      204); // post ID
    
  • I am sure that the post_id is 204, but i am not quiet sure about the value of the user. The sub field is a user field. Does it even accept ‘user_3’ as value or do i need to specify only the user id?

  • It does not matter what the values are, you have them backwards.

    argument 2 should be the value
    argument 3 should be the post ID — ‘user_3’

  • Unfortunately this isn’t the case. To test if these rows even exist i tried this:

    
    if (function_exists('have_rows')) {
            while (have_rows('field_61c18b86ee6fd')) {
                dd('test');
            }
        }
    

    This did not return the expected ‘test’, ‘field_61c18b86ee6fd’ is the key of the repeater. I tied to use the sub fields key and this also didn’t return the expected ‘test’. I wondered what it could be until i found this.

    In the database there is a related_player_0_reservation_participant and a _related_player_0_reservation_participant the related_player_0_reservation_participant was not filled with an id. Updating this field like so: update_field('related_player_0_reservation_participant', 1, 204); did the trick for me. Anyways thanks for your help.

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

You must be logged in to reply to this topic.