Support

Account

Forum Replies Created

  • That works!!!

    There are a few posts that are empty though. I’m not sure why, but this at least puts me on the right direction. Thank you so much for your help!!!

  • Right now it’s just a php script that is called when I manually call it. I will make a cron job for it so that it runs probably once a night or so.

    Yes each [$i] should be it’s own post. I’m sorry I didn’t make that clear when I posted at the beginning. And so far that isn’t working either. I know it has something to do with the ordering of the loop but I’m trying to understand it. I accidentally put wp_insert_post call in the wrong place and created over 300 posts that I had to delete. Oops. Haha. But when I did that, none of the fields were populated. So I know it has to be how I have things ordered. I really appreciate you walking through this with me to help me understand what’s going on.

  • When I print and update_field(), it is in an infinite loop for the print. It does create a post with the title of “test”, but none of the fields are populated.

  • Not that I can find. When I run it in the terminal it doesn’t do anything and I have to press Ctrl+Z to stop it.

  • 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.

    <?php
    
    function readCSV($csvFile){
        $file_handle = fopen($csvFile, 'r');
        while (!feof($file_handle) ) {
            $line_of_text[] = fgetcsv($file_handle, 1024);
        }
        fclose($file_handle);
        return $line_of_text;
    }
    
    $csvFile = 'data/dtas-inventory.csv';
    
    $inventory = readCSV($csvFile);
    
    $field_keys = array(
        'field_58c95667b0f7d',
        'field_58c956c86747a',
        'field_58c9576a1f775',
        'field_58c957951f776',
        'field_58c9581639a32',
        'field_58c9582739a33',
        'field_58c9583339a34',
        'field_58c9583d39a35',
        'field_58cc131c5f7ac',
        'field_58c958ad3dae4',
        'field_58c958b53dae5',
        'field_58c958bb3dae6',
        'field_58c958c63dae7',
        'field_58c958dc942c8',
        'field_58cc138e09213',
        'field_58c958f1942c9',
        'field_58cc13ba6995a',
        'field_58c95901942ca',
        'field_58c959189521f',
        'field_58c9592195220',
        'field_58c9592795221',
        'field_58c9593195222',
        'field_58c9594495223',
        'field_58c9596595224',
        'field_58c959dd2451a',
        'field_58cc13f66995b',
        'field_58cc140c6995c',
        'field_58cc141c6995d',
        'field_58c95a102451b',
        'field_58cc142b6995e',
        'field_58cc143b6995f',
        'field_58cc145169960',
        'field_58c95a2d3ded4',
        'field_58cc146269961',
        'field_58cc146e69962',
        'field_58cc147869963'
    );
    
    $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.

Viewing 6 posts - 1 through 6 (of 6 total)