Via: https://felicoz.com/en/2017/05/acf-import-repeater-field-values-csv-programmatically/
- Prepare your CSV file with columns matched to the repeater sub fields
- ACF – create a csv file select field
- ACF – set up the repeater field with sub fields
- create a new post
- From the post, upload your csv
- create empty repeater fields depending on the number of rows you have in csv
- In the front page, paste this php code:
<?php
if(get_field('csv_file'))
{
// load csv with SERVER PATH instead of URL
$csv = get_attached_file(get_field('csv_file')['id']);
if(($handle = fopen($csv, "r")) !== FALSE)
{
$count=0;
while(($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
// $count = acf row, $data[0] = csv column 1 value
update_sub_field(array('repeater_name', $count, 'name'), $data[0]);
update_sub_field(array('repeater_name', $count, 'address'), $data[1]);
update_sub_field(array('repeater_name', $count, 'phone'), $data[2]);
$count++;
}
fclose($handle);
}
}