Momen Zalabany
Momen Zalabany

Reputation: 9007

import posts to wordpress from another custom database

database schema.

ID    title    keywords    category    body      time
1      XX      demo,tag      main      <html>    NOW()
2      YY      demo2,tag     main      <html>    NOW()

this database is frequently updated by another webapp.

my question is how can i post create a custom php file that can handle posting new records from this table into wordpress ?

i found wp_insert_post api when i googled around, but they mentioned that this wonnt create category if its not there.

  foreach($data as $db){
  $my_post = array();
  $my_post['post_title'] = $db->title;
  $my_post['post_content'] = $db->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->keywords);///IS THIS CORRECT??

// Insert the post into the database
  wp_insert_post( $my_post );}

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 ?

thanks alot

Upvotes: 2

Views: 1067

Answers (1)

Ilya
Ilya

Reputation: 179

you can create category using wp_create_category - your import script should analyze the source data and create categories if necessary first

Upvotes: 1

Related Questions