Home Forums Add-ons Repeater Field Delete, update and adding rows in template files


Delete, update and adding rows in template files

  • Hi there

    I did a search and read the update_field documentation but i’m a little confused.

    I basically just want to be able to update a post’s repeater data from my template files.

    So i have a post (ID 512) which has a repeater called ‘users’ which has ‘name’, ‘surname’, telephone’ text fields.

    I looked in the DB and these are stored as documented so:

    udetails_1_name – ‘dave’
    _udetails_1_name – ‘field_532b122e8afe1’

    udetails_2_name – ‘mark’
    _udetails_2_name – ‘field_532b122e8afe1’


    My question is how do i use the update_field function to say change dave’s name to ‘paul’ or remove mark all together (along with his second name and telephone).

    I am confused as to how the function:
    update_field($field_key, $value, $post_id)

    How the field key in this case is the same for both ‘rows’ so if i did:
    update_field(‘field_532b122e8afe1’, ‘whatever’, 512)

    this does not target any of the repeater’s data rows specifically.

    Also how would you go about deleting a row from the front end or adding one in? I could do it manually i guess with SQL but maintaining the correct sequence of:


    etc will be tricky and i’d rather use your inbuilt functions…. just totally stuck as to how to go about it.


  • After a bit more reading i think where i am confused is that maybe that you use update_field each time to add in all rows at once?

    So you’d have a multidemensional array off ‘all’ of the rows which then bulk overrides?

    If so does that mean you use the field_key of the actual repeater?

    udetails – 2
    _udetails – field_532b0f308afe0

    update_field(‘field_532b0f308afe0′, $multi-demensional-array, 512)

    If this is correct what would the array be structured like in my case?

    $multi-demensional-array = array(
    [0] -> array('field_532b122e8afe1' => 'paul', ''field_532b123c8afe2' => 'brown')
    [1] -> array('field_532b122e8afe1' => 'mark', ''field_532b123c8afe2' => 'smith')

    right so i tried this on another post

    $udata = array(array('field_532b122e8afe1' => 'paul', 'field_532b123c8afe2' => 'brown'));	 
    update_field('field_532b0f308afe0', $udata, 654);

    added in perfectly so think i have answered my own question :D. I guess the technique to just amend one row would be to build up the above array with the change and all of the previous data. Seems a bit counter-intuitive but i guess writing an add/delete row function is a pain in the a$$ as you’d have to deal with maintaining the sequential meta keys as opposed to just re-creating them as i assume the update_field function does.

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

The topic ‘Delete, update and adding rows in template files’ is closed to new replies.