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 );
Did you mean to post a link to another topic for more of an example?
I’m really not sure that you’re doing with your code. Since this is for a custom post type what you have in $user_id
I think should just be the post_id of the post.
update_field also works better if you use the field key which looks something like field_123456789abcde
. For more on field keys see the documentation for update_field http://www.advancedcustomfields.com/resources/update_field/
You should also take a look at update_sub_field http://www.advancedcustomfields.com/resources/update_sub_field/