Following code will be used for adding multiple entries to
<?php
// This is needed to use WP functions.
require_once('../wp-load.php');
//echo "%%%%". preg_replace("/:/", " ", "21-Dec-2010:10:37:27", 1);
// Category tables are
// wp_terms here term_id will present category_id,
// wp_term_relationship show relationships with posts.
// wp_term_taxonomy-for total post count
// 4= oracle, 10-sqlscripts
// Read file and disect in different field.
$fh= fopen('UNIX.txt','r');
$lineno = 0;
while ($line = fgets($fh))
{
if ( strstr($line, "#################") ) {
//////////////////////// First line of post
echo "POST#" . "<br>";
echo "- - - - - - - - - - - - - - - - - - - - - - -- - - - -- - - " ."<br>";
if ($lineno != 0)
{
$new_post = array(
'post_title' => $v_title,
'post_content' => $v_content,
'post_status' => 'publish',
'post_date' => date("Y-m-d h:i:sa", strtotime($v_timeStamp)),
'post_category' => array(16,7)
);
$post_id = wp_insert_post( $new_post );
if( $post_id ){
echo "Post inserted successfully with the post ID of ".$post_id;
} else {
echo "Error, post not inserted";
}
}
$lineno = 0;
// echo "v_content=" . $v_content;
$v_content="";
}
else {
// echo "line number=" . $lineno . "<br>";
if (strstr($line, "Date >>-->") )
{
// Extracting time stamp
$v_timeStamp= substr($line, 11);
$v_timeStamp = preg_replace('/:/', ' ', $v_timeStamp, 1);
echo "v_timestamp = ". $v_timeStamp;
}
elseif (strstr($line, "Title >>-->" ) )
{
// Extract Title
$v_title= substr($line, 12);
echo "v_title = ". $v_title;
}
else
{
// Populate contents by appending them
$v_content .= $line . "<br>";
}
$lineno = $lineno + 1;
}
}
fclose($fh);
?>
