This is how I managed to fix it, Thanks to Stephen Harris.
add_action('save_post', 'parse_csv', 10, 2);
function parse_csv($post_id) {
$_pid = $post_id;
// Autosave, do nothing
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// AJAX? Not used here
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
return;
// Check user permissions
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
// Return if it's a post revision
if ( false !== wp_is_post_revision( $post_id ) )
return;
if('phone' == $_POST['post_type']) {
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
$csv_file = get_post_meta($post_id, 'plan_information', TRUE);
$csv_file = wp_get_attachment_url($csv_file);
$title = get_post_meta($post_id, 'manufacturer', TRUE). ' '.get_post_meta($post_id, 'model', TRUE).' '.get_post_meta($post_id, 'memory', TRUE);
$url = get_bloginfo('wpurl')."https://wordpress.stackexchange.com/";
$csv_file = str_replace($url, ABSPATH, $csv_file);
$carriers = get_posts(array('post_type' => 'carrier', 'meta_key' => 'phone_id', 'meta_value' => $_pid));
update_post_meta($_pid, "_wp_page_template", "phone-page.php");
if($csv_file && !$carriers) {
$fp = fopen($csv_file,"r");
if($fp) {
fgetcsv($fp, 1000, ",");
while (($data = fgetcsv($fp, 1000, ",")) !== FALSE)
{
$new_carrier = array(
'post_title' => $title . '-' .$data[3],
'post_status' => 'publish',
'post_type' => 'carrier'
);
$post_id = wp_insert_post($new_carrier);
add_post_meta($post_id, 'operator', $data[0], true);
add_post_meta($post_id, 'logo', $data[1], true);
add_post_meta($post_id, 'cost', $data[2], true);
add_post_meta($post_id, 'plan_name', $data[3], true);
add_post_meta($post_id, 'hero', $data[4], true);
add_post_meta($post_id, 'summary', $data[5], true);
add_post_meta($post_id, 'phone_id', $_pid, true);
}
fclose($fp);
}
}
}
}