Home Forums ACF PRO Add rows to a repeater field


Add rows to a repeater field

  • 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

    You should also take a look at update_sub_field

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

The topic ‘Add rows to a repeater field’ is closed to new replies.