I'm looking for a way to add rows to a repeater field in ACF Pro. I found this post but the solution post doesn't seem to work. I will describe my problem:
I have a custom post type called "gebruikers", a repeater field called "logins" and a rows that can have a field called "datum". I would like to be able to add a value to a new row in the field "datum". Is this possible?
My code so far:
$field_key = "logins";
$user_id = "gebruiker_23";
$value = get_field($field_key, $user_id);
$value[] = array('date' => date('Y-m-d H:i:s'));
update_field( $field_key, $value, $user_id );*/
Finally figured this out!
Change $field_key = "logins"; to the field key that is in the Wordpress posts table. Grab the field_id from there (post_name column) that is assigned to your main repeater field.
Use the ID from post_name.
Now you can insert to these records if none already exist.
Example that worked for me on a user record with no previous rows:
$field_key = "field_5657dffe586cc";
$value = get_field($field_key, 'user_24');
$value[] = array("career_enjoyment_id" => "Foo", "career_enjoyment_file" => "Bar");
update_field( $field_key, $value, 'user_24' );
I think the add_row function is what you are looking for. https://www.advancedcustomfields.com/resources/add_row/
$row = array(
'datum' => 'new value',
);
$i = add_row( 'logins', $row );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With