I have a Custom Post Type called movies
which had only title enabled from post support and 3 custom field of metabax as box office
, year
, and director
like
now I have like 150 rows CSV formatted stored data whith same structure as
name, boxoffice,year,director
can you please let me know how I can load them into WP database to keep both Custom Post Type and metadat in the database using PHP
I have a Custom Post Type called movies
which had only title enabled from post support and 3 custom field of metabax as box office
, year
, and director
like
now I have like 150 rows CSV formatted stored data whith same structure as
name, boxoffice,year,director
can you please let me know how I can load them into WP database to keep both Custom Post Type and metadat in the database using PHP
if(isset($_POST["submit"]))
{
$rows = array();
if($_FILES['file']['name'])
{
$filename = explode(".", $_FILES['file']['name']);
if($filename[1] == 'csv')
{
$handle = fopen($_FILES['file']['tmp_name'], "r");
$count=0;
while(($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
query_posts(array(
'post_type' => 'custom-post-type',
) );
while(have_posts()) : the_post();
$post_id->ID;
$rows[] = array(
'variable1' => $data[1] . "," . $data[2] . "," . $data[3] . "," . $data[4],
//above line for using multiple cells of csv file to a single variable
'variable2' => $data[5],
'variable3' => $data[6],
'variable4' => $data[7],
'variable5' => $data[8],
'variable6' => $data[9]
);
endwhile;
$count++;
}
foreach($rows as $row => $rowValue ){
add_row('rates', $rowValue, $post_id);
}
fclose($handle);
}
}
}