1
I have an example code to create a Post of a specific type (product from WooCommerce) and would like to use it to make a routine import of many products. 
<?php 
    function createNewProduct() {
        $new_post = array(
            'post_title' => "Custom Variable Test",
            'post_content' => 'Lorem ipsum dolor sit amet...',
            'post_status' => 'publish',
            'post_type' => 'product'
        );
        $skuu = 'custom-prod-1';
        $post_id = wp_insert_post($new_post);
        echo 'post_id = ' . $post_id;
        update_post_meta($post_id, '_sku', $skuu );
        update_post_meta( $post_id, '_price', "25" );
        wp_set_object_terms( $post_id, 'Gasolina', 'pa_fuel' );
        wp_set_object_terms( $post_id, 'Ford', 'pa_brand' );
        update_post_meta( $post_id, '_visibility', 'search' );
        update_post_meta( $post_id, '_stock_status', 'instock');
        // Lendo o Post criado
        $content_post = get_post($post_id);
        $content = $content_post->post_content;
        // $content = apply_filters('the_content', $content);
        // echo '<pre>' . print_r($content, true) . '</pre>';
        // echo '<pre>' . print_r($content_post, true) . '</pre>';
    }
?>
I’d like to know the best approach to importing the data. When I put this routine in a plugin and enable by the visual interface Wordpress executes the code numerous times creating repeated records. When I run the PHP file alone it accuses error Fatal error: Call to undefined function.
Any good practice tips to be used for this type of problem ?
Thanks. I’ll try it, thanks
– bmkrio