pavelbohovin
7/23/2015 - 11:17 AM

import_from_csv.php

<?php
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');

if (($handle = fopen("import_handbook16febr.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $post_title = $data[0];
        $post_content = $data[1];
        $menu_order = $data[2];
        $post_date = $data[3];
        $post_date_gmt = $data[4];

		$post_data = array(
			'post_title'    => $post_title,
			'post_content'  => $post_content,
			'post_status'   => 'publish',
			'post_type'     => 'handbook',
			'post_date'     => $post_date,
			'post_date_gmt' => $post_date_gmt,
			'post_author'   => 1,
			'menu_order'    => $menu_order
		);

		$post_id = wp_insert_post( $post_data );
        echo $post_id . ",\n";
    }
    fclose($handle);
}