title: import posts to wordpress from another custom database
body: <p>database schema.</p>
  
  <pre><code>ID    title    keywords    category    body      time
  1      XX      demo,tag      main      &lt;html&gt;    NOW()
  2      YY      demo2,tag     main      &lt;html&gt;    NOW()
  </code></pre>
  
  <p>this database is frequently updated by another webapp.</p>
  
  <p>my question is how can i post create a custom php file that can handle posting new records from this table into wordpress ?</p>
  
  <p>i found <a href="http://codex.wordpress.org/Function_Reference/wp_insert_post" rel="nofollow">wp_insert_post</a> api when i googled around, but they mentioned that this wonnt create category if its not there.</p>
  
  <pre><code>  foreach($data as $db){
    $my_post = array();
    $my_post['post_title'] = $db-&gt;title;
    $my_post['post_content'] = $db-&gt;body;
    $my_post['post_status'] = 'publish';
    $my_post['post_author'] = 1;
  
    //$my_post['post_category'] = array(8,39);//how to fetch the category id !
    //$my_post['tags_input'] = explode(',',$db-&gt;keywords);///IS THIS CORRECT??
  
  // Insert the post into the database
    wp_insert_post( $my_post );}
  </code></pre>
  
  <p>so can some one please explain how can i export a db into a wordpress post with category (create if not exist),tags,title,timedate and content ?</p>
  
  <p>thanks alot</p>