I have group fields inside repeater field. I want to update the value of specific group field value programmatically.
Example – Below is an array of repeater field.
Array
(
[0] => Array
(
[booking_list] => Array
(
[termin] => November 20, 2021 12:00 am
[available_seats] => 5
)
)
[1] => Array
(
[booking_list] => Array
(
[termin] => November 30, 2021 12:00 am
[available_seats] => 6
)
)
)
**I want to update the value of available_seats field
Edited -:
I tried this code but not working.
if( have_rows('booking') ) {
$i = 0;
while( have_rows('booking') ) {
the_row();
$i++;
if(have_rows('booking_list')){
while( have_rows('booking_list') ){
the_row();
update_sub_field('available_seats', 2);
}
}
}
}
Screenshot
Click Me
3
Answers
You can use the
update_field
also. You just need to see themeta-key
in the database. It is usually stored like this:parent_booking_list_available_seats
. Of course not "parent" you need to have a look in the database.My personal approach is to use
get_field
and since it returns an array, you can just loop through different items and update the fields where necessary.Below snippet would make all available_seats to 2. You can introduce conditional logic if needed.
If you Still need an answer.
This will update a grouped field inside a repeater field.
Repeater > Group > Group Field 1
That’s how I made it. Hope this will help you! @kamal