Updating Wordpress database with CSV file

I need to update a wordpress database using a CSV file. My code is generating some errors.

function updatedb( ) {
$myfile = fopen("/test.csv", "r") or die("Unable to open file!");
$csvArray = array_map('str_getcsv', file($myfile));
global $wpdb;

foreach($csvArray as $csvEntry) {

$value = $csvEntry[2]
$datafield = $csvEntry[1]
$sku = $csvEntry[0]
        array(  meta_value => $value,
        array(  meta_key => $datafield AND
                       post_id => (select post_id
                                              from (select
                                                             from ppwp_postmeta
                                                             where meta_key = '_sku') as sku_post
                                                             where meta_value = $sku);


I am using a wordpress cron job to repeat this once an hour.

// Schedule Cron Job Event
function update_stock_cron_job() {
if ( ! wp_next_scheduled( ‘updatedb’ ) ) {
wp_schedule_event( time(), ‘hourly’, ‘updatedb’ );
add_action( ‘wp’, ‘update_stock_cron_job’ );

I have little experience with PHP or Wordpress, so advice on where I’m going wrong would be appreciated.

And those errors are … ?

In all honesty, every time I change part of the code I get an error of some kind! :frowning:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.