Add CPT values to Database

Assuming you can get all your CPT data in a .csv file, you should be able to write a function that can import it. I have done this for bringing in user tables and/or custom posts when clients migrate from an existing site or software. Here is some example code. You could run this as an include in functions or as part of your plugin, then disable it if you don’t need it after the start:

// always find line endings
ini_set('auto_detect_line_endings', true);

// add admin menu
add_action('admin_menu', 'csvimporter_menu');

function csvimporter_menu() {   
    add_submenu_page( 'edit.php?post_type=physician', 'CSV Importer', 'Import', 'manage_options', 'csv-importer', 'csvimporter');   
}

// show importer form
function csvimporter() {
    global $wpdb;
    if (!current_user_can('manage_options')) {
        wp_die( __('You do not have rights to access this page.') );
    }

    // when form is submitted
    if ($_POST['mode'] == "submit") {

        $arr_rows = file($_FILES['csv_file']['tmp_name']);

        // process the rows
        if (is_array($arr_rows)) {
            foreach ($arr_rows as $row) {

                // split into values -- note I prefer to separate by semicolon, you must setup your CSV to match this delimiter
                $arr_values = split(";", $row);

                // these will need rekeyed!! this is just an example!! In this example I build a long title from the physician's name
                $name    = $arr_values[0]; //fname
                $name   .= (empty($arr_values[1]) ? '' : ' '  .$arr_values[1]); //mname
                $name   .= (empty($arr_values[2]) ? '' : ' '  .$arr_values[2]); //lname
                $name   .= (empty($arr_values[3]) ? '' : ' '  .$arr_values[3]); //suffix
                $name   .= (empty($arr_values[4]) ? '' : ', ' .$arr_values[4]); //first degree
                $name   .= (empty($arr_values[5]) ? '' : ', ' .$arr_values[5]); //second degree

                // add the new post
                $arr_post = array(  'comment_status' => 'closed',
                                    'ping_status' => 'closed',
                                    'post_author' => 1,
                                    'post_title' => $name,
                                    'post_status' => 'publish', 
                                    'post_type' => 'physician',                                 
                                    );
                $post_id = wp_insert_post( $arr_post );

                // add all the meta values
                $arr_meta_values = array(
                    '_cmb_last_name'    => $arr_values[2],
                    '_cmb_board_1'      => $arr_values[6],
                    '_cmb_board_2'      => $arr_values[7],
                    '_cmb_group_name'   => $arr_values[11],
                    '_cmb_address_1'    => $arr_values[12],
                    '_cmb_address_2'    => $arr_values[13].(!empty($arr_values[14]) ? ', '.$arr_values[14] : ''),
                    '_cmb_city'         => $arr_values[15],
                    '_cmb_state'        => $arr_values[16],
                    '_cmb_zip'          => $arr_values[17],
                    '_cmb_phone'        => $arr_values[18],
                    '_cmb_status'       => $arr_values[19]
                );

                // fill up terms if you wish
                $taxonomy = 'physician-specialty';
                $terms = array();
                if(!empty($arr_values[8])){
                    // get ID if is term
                    $term_id = is_term($arr_values[8]);
                    if($term_id != 0){
                        // is term, add to list
                        $terms[] = $term_id;
                    } else {
                        // is not term, create, then add to list
                        wp_insert_term($arr_values[8], $taxonomy);
                        $term_id = is_term($arr_values[8]);
                        $terms[] = $term_id;
                    }
                }
                // assuming more term columns are there...
                if(!empty($arr_values[9])){
                    $term_id = is_term($arr_values[9]);
                    if($term_id != 0){
                        $terms[] = $term_id;
                    } else {
                        wp_insert_term($arr_values[9], $taxonomy);
                        $term_id = is_term($arr_values[9]);
                        $terms[] = $term_id;
                    }
                }
                // add all terms at once
                wp_set_post_terms($post_id, $terms, $taxonomy);

                foreach($arr_meta_values as $key => $value) {
                    update_post_meta($post_id, $key, $value);
                }
            }

            $html_update = "<div class="updated">It worked! I think.</div>";
        } else {
            $html_update = "<div class="updated" style="color: red">Something went terribly wrong!</div>";          
        }
    }
    ?>
    <div class="wrap">  
        <?php echo $html_update; ?> 
        <div id="icon-plugins" class="icon32"><br /></div>
        <h2>CSV Importer</h2>
        <p>Select the CSV file you want to import</p>

        <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="mode" value="submit">
            <input type="file" name="csv_file" />       
            <input type="submit" value="Import" />
        </form>

        <p>The CSV file should be in this sweet, sweet format. Oh yea!</p>

        <table>
            <tr>
                <td>firstname;</td>
                <td>middlename;</td>            
                <td>lastname;</td>
                <td>blah;</td>
                <td>etc;</td>
            </tr>
        </table>

        <p style="color: red">Please make sure you back up your database before proceeding!</p> 
    </div>
    <?php
}
?>

You’ll need to make sure your CSV is setup properly. I strongly suggest backing up database and running only a sample dataset (20 rows) to ensure this is working properly. Note my example has only a sampling of my own data needs. The end result can include many more meta_keys, taxonomy stuff, actual content, etc. Just be sure you choose a good delimiter for your CSV. Excel might not let you setup the CSV just how you want, I recommend OpenOffice.