How to import database table as custom post type and custom fields?

// There’s a confusion in which method you are importing your external table into WordPress. If someway you have parsed you external table data into a PHP variable ex: $data, then it would be simple to import.

foreach( $data as $_dt )
{
    $new_id = wp_insert_post( array(
        'post_type' => 'vehicle',
        'post_status' => 'publish',
        'post_title' => $_dt['vehicle_name']
    ));
    if( !is_wp_error($new_id) )
    {
        update_post_meta($new_id, "stockNumber", $_dt["stockNumber"]);
        update_post_meta($new_id, "vin", $_dt["vin"]);
        update_post_meta($new_id, "make", $_dt["make"]);
    }
}

// Now regarding the data source, if you have already imported your custom table into your WordPress Database, use this simple code to grab the data from it –

$data = $wpdb->get_results("SELECT * FROM $your_table_name");