Support

Account

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

  • I think I see what’s going on, maybe this will help

    
    for ($i = 1, $numInventory = count($inventory); $i < $numInventory; $i++) {
      
      // for each row of the input, create a new post
      $post_information = array(
          'post_title'    =>  'test '.$i,
          'post_type'     =>  'vehicle',
          'post_status'   =>  'publish'
      );
      $postID = wp_insert_post( $post_information );
      
      // the following assumes that the order of 
      // the columns in the csv matches
      // the order of the list of field keys
      
      for ($m = 0, $numSub = count($inventory[$i]); $m < $numSub; $m++) {
        
        // use the field key for $m column
        update_field($field_keys[$m], $inventory[$i][$m], $postID);
        
      } // end for $m
      
    } // end for $i