Support

Account

Home Forums General Issues Adding rows into a Repeater Field programatically Reply To: Adding rows into a Repeater Field programatically

  • Inserting repeater fields into the DB is something I’ve just needed to do myself. There are a lot of fields to deal with.

    Each repeater field contains the number of rows of sub-fields.
    Each sub-field is actually named {repeater-name}_{count}_{subfield-name}

    So you need to insert the number of rows into “latlng_repeater”
    then for each row, say you have 2, you insert the values into:

    • latlng_repeater = 2
    • latlng_repeater_0_latlng_repeater_item_lat = lat value 1
    • latlng_repeater_0_latlng_repeater_item_long = long value 1
    • latlng_repeater_1_latlng_repeater_item_lat = lat value 2
    • latlng_repeater_1_latlng_repeater_item_long = long value 2

    To top this off, each of these fields has a corresponding field that starts with an _ whose value is the ACF field key. I had cases when working on my import where I needed to insert these values to get the field values to show on the front end without needing to open and save every post in the admin. I also has some cases where the imported values did not even appear in the admin without inserting these.

    • _latlng_repeater = field_53cf18c22ee37
    • _latlng_repeater_0_latlng_repeater_item_lat = field_53cf19022ee3b
    • _latlng_repeater_0_latlng_repeater_item_long = field_53d09ad6527ac
    • _latlng_repeater_1_latlng_repeater_item_lat = field_53cf19022ee3b
    • _latlng_repeater_1_latlng_repeater_item_long = field_53d09ad6527ac

    You really need to add some posts with all of the fields and then dig around in the database to figure out what you need to insert.

    Hope that helps.

    ~JH