手动创建用户,并等到用户ID,用户ID在
wp_users
表中 分类需要手动添加,添加分类之后,在wp_terms
表中找到term_id
,然后再根据找到的term_id
到wp_term_taxonomy
表中找对应的term_taxonomy_id
这个文章写入方法已经有改进版
//常量
$userID = 291;//发布者ID
$tagID = 297;//分类ID
$post = new T();//初始化POST库
//文章表操作
$post->post_author = $userID;//发布者ID
$post->post_date = date ( 'Y-m-d H:i:s' );//发布时间
$post->post_date_gmt = date ( 'Y-m-d H:i:s' , time () - date ( 'Z' ) );//格林威治时间
$post->post_title = '新华社消息';//文章标题
$post->post_content = '白宫被中国土豪全资购买';//文章内容
$post->post_status = 'publish';//文章状态
$post->comment_status = 'open';//文章评论状态
$post->ping_status = 'open';//ping状态
$post->post_modified = date ( 'Y-m-d H:i:s' );
$post->post_modified_gmt = date ( 'Y-m-d H:i:s' , time () - date ( 'Z' ) );
$post->save ();//写入数据库
$aid = $post->ID;//刚入库的文章ID
$rela = new rela();//初始化wp_term_relationships库
$rela->object_id = $aid;
$rela->term_taxonomy_id = $tagID;
$rela->term_order = 0;
$rela->save ();
$te = new terms();//初始化wp_term_taxonomy库
$te->where ( 'term_taxonomy_id' , '=' , $tagID )->increment ( 'count' );
//循环四次写入数据库
for ( $i = 0 ; $i < 4 ; $i++ ) {
$meat = new postmeat();//初始化wp_postmeta库
$meat->post_id = $aid;//文章ID
switch ( $i ) {
case 0:
$meat->meta_key = '_edit_lock';
$meat->meta_value = time () . ':' . $userID;
$meat->save ();
break;
case 1:
$meat->meta_key = '_edit_last';
$meat->meta_value = $userID;
$meat->save ();
break;
case 2:
$meat->meta_key = 'fromname_value';
$meat->meta_value = '新华社';
$meat->save ();
break;
case 3:
$meat->meta_key = 'fromurl_value';
$meat->meta_value = 'http://news.baidu.com';
$meat->save ();
break;
}
}