Support

Account

Home Forums Add-ons Repeater Field Update_field not working for subfields

Helping

Update_field not working for subfields

  • I’m trying to use update_field to change a value in a sub field with the following code but it is not changing. This is my following code:

    
    if( get_field('image_gallery', $id) )
        {
        	while( has_sub_field('image_gallery', $id) )
        	{
        	update_field('field_4f7b11d3e7729', 10702, $id);
        	echo get_sub_field('image');
        	}
        }

    I’m expecting “10702” to be printed but it’s original value isn’t changing.

    This is my repeater field:

    array (
                    'key' => 'field_9',
                    'label' => 'Image Gallery',
                    'name' => 'image_gallery',
                    'type' => 'repeater',
                    'order_no' => 1,
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' =>
                    array (
                        'status' => 0,
                        'allorany' => 'all',
                        'rules' => 0,
                    ),
                    'sub_fields' =>
                    array (
                        0 =>
                        array (
                            'key' => 'field_4f7b11d3e7729',
                            'label' => 'Image',
                            'name' => 'image',
                            'type' => 'image',
                            'save_format' => 'id',
                            'preview_size' => 'thumbnail',
                            'order_no' => 0,
                        ),
  • Hi @rli1369

    Currently, the update_field is not able to update a sub field. This is a limitation of the architecture of ACF as it uses post meta to save the field object.

    In the future, we will see an update_sub_field function

    Thanks
    E

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

The topic ‘Update_field not working for subfields’ is closed to new replies.