Home Forums General Issues Inserting CSV data into custom fields Reply To: Inserting CSV data into custom fields

  • Well it works regardless of the numbers in the brackets (as long as it exists in the array of course.)

    The reason I started with zero was because the headers are in the first array and I wanted to bypass those.

    This is my full code.

    function readCSV($csvFile){
        $file_handle = fopen($csvFile, 'r');
        while (!feof($file_handle) ) {
            $line_of_text[] = fgetcsv($file_handle, 1024);
        return $line_of_text;
    $csvFile = 'data/dtas-inventory.csv';
    $inventory = readCSV($csvFile);
    $field_keys = array(
    $post_information = array(
        'post_title'    =>  'test',
        'post_type'     =>  'vehicle',
        'post_status'   =>  'publish'
    $postID = wp_insert_post( $post_information );
    foreach($field_keys as $field_key) {
        for ($i = 1, $numInventory = count($inventory); $i < $numInventory; $i++) {
            for ($m = 0, $numSub = count($inventory[$i]); $m < $numSub; $m++) {
                update_field($field_key, $inventory[$i][$m], $postID);
                //print "Record [$i][$m] is " . $inventory[$i][$m] . "\n";

    So if I comment out the updatefield() function and uncomment the print line, it prints what is expected to the terminal. But when I use the update_field() function and run the php script in the terminal it just hangs. But if I replace $inventory[$i][$m] with $inventory[2][5] (or anything that exists) it goes straight in the correct fields.

    I’m really at a loss as to why it isn’t working.