Home › Forums › General Issues › Import ACF Repeater Field Values from CSV
I’m trying to import a load of data into a sub fields of a repeater field (mortgage_providers) using file field (dd_csv) to upload the file to a post and return an array. Then loop through each row with PHP and update the repeater fields. I have tried the following but I can’t seem to get it to work.
if( get_field('dd_csv') ) {
// load csv with SERVER PATH instead of URL
$csv = get_attached_file(get_field('dd_csv')['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('mortgage_providers', $count, 'mortgage_provider_name'), $data[0], 'option');
$count++;
}
fclose($handle);
}
}
Here’s a sample of the data:
at symbol Sipp
012 Property Shares
121 Legals
1st Source Direct
1st Stop Finance
33 KWS
3i
3M
3mc
3XD
5 Arrows
AA Commercial Insurance
AIG
A1 Lender not relevant
AA Friendly Society
AA Insurance
Abacus
…
In total there’s over 1000 rows in column 1 of the CSV.
Thanks
I just ran into a very similar problem trying to import a whole load of data from a csv into a repeater, might be useful for anyone looking at how to do this in future
https://medium.com/@alexjeffers/importing-data-from-a-csv-file-into-a-wordpress-acf-repeater-field-c411c642a54c
You can use a non-programmatic method, such as a plugin like CSV Importer Plus for ACF: https://wordpress.org/plugins/csv-importer-plus-for-acf/.
Watch the video tutorial here: https://csvimporterplusforacf.com/import-acf-repeater-field-values-from-csv/
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.