Support

Account

Home Forums Add-ons Repeater Field Update field with repeater + relationship

Helping

Update field with repeater + relationship

  • Hi
    How can we update relationship with repeater field? We have repeater field:

    Sponsor -> field name(repeater field)
    Select sponsors -> Sub field.(relationship)

    Now we want to update select sponsors field,I know how to update relationship field standalone means without repeater field but stuck with repeater field.

    update_field('select_sponsers',array(1142,1141), '102');

    looking forward to solution 🙂
    Thanks
    Ahir

  • When you update the repeater field the values need to be in a nested array, you will also need to use field keys instead of field names.

    
    // replace field keys with your real field keys
    // Sponsor -> field name(repeater field) - field key (field_XXXXXXX')
    // Select sponsors -> Sub field.(relationship) - field key (field_YYYYYYY')
    $repeater_value = array(
      // each nested array is a row in the repeater
      array(
        // each row contains field key => value pairs for each sub field
        // select field
        'field_YYYYYYY' => array(1142,1141)
      )
    )
    // update field using repeater field key
    update_field('field_XXXXXXX', $repeater_value, $post_id);
    

    alternately you can use update sub field explained here https://www.advancedcustomfields.com/resources/update_sub_field/

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

The topic ‘Update field with repeater + relationship’ is closed to new replies.