I would hook into the on save action:
<?php
add_action( 'save_post', 'prefix_check_files', 10, 3 );
function prefix_check_files( $post_id, $post, $update ) {
if( get_field('dd_csv', $post_id) ) {
// load csv with SERVER PATH instead of URL
$csv = get_attached_file(get_field('dd_csv', $post_id)['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);
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…