【发布时间】:2014-10-20 16:47:50
【问题描述】:
我想将自定义数据库中的类别和文章导入到 wordpress 类别和帖子中。任何想法、提示或代码 sn-p 将不胜感激。
谢谢你和问候。
【问题讨论】:
我想将自定义数据库中的类别和文章导入到 wordpress 类别和帖子中。任何想法、提示或代码 sn-p 将不胜感激。
谢谢你和问候。
【问题讨论】:
基本上你要做的就是将你的记录插入到 Wordpress 的wp_posts 表中。该表有以下字段(当然如果你使用的是最新的 3.9.2 版本):
ID - (no explanation needed, it is auto-increment value)
post_author - (here in your case put 1 - this is Administrator account)
post_date - (no explanation needed)
post_date_gmt - (same as above, but date is GMT)
post_content - (your article content, HTML code, if any, may or may not be escaped)
post_title - (no explanation needed)
post_excerpt - (can be empty in your case)
post_status - (there are six of them, in your case put "publish" or "draft" if you want manually to make post visible at later stage)
comment_status - (put "closed" if you want to disable comments or "open" otherwise)
ping_status - (same as above, but it applies for ping)
post_password - (put empty string)
post_name - (put lowercase converted post title, but replace spaces with "-", this is URL friendly version of the post name, ex: my-first-post-title)
to_ping - (put empty string)
pinged - (put empty string)
post_modified - (put date of the post)
post_modified_gmt - (same as above, but date is GMT)
post_content_filtered - (put empty string)
post_parent - (put 0 initially, later you can build your post hierarchy)
guid - (URL of the post, http://www.yourdomain.com/?page_id=the_ID_of_the_post)
menu_order - (put 0)
post_type - (put "page" or "post", there is a difference though)
post_mime_type - (put empty string)
comment_count - (put empty string)
以下是成功插入所需的最低值的示例 SQL 查询:
INSERT INTO wp_posts (post_author,post_date,post_date_gmt,post_content,post_title,post_excerpt,
post_status,comment_status,ping_status,post_password,post_name,to_ping,pinged,
post_modified,post_modified_gmt,post_content_filtered,post_parent,guid,
menu_order,post_type,post_mime_type,comment_count)
VALUES (1,'2014-08-28 02:00:00', '2014-08-28 00:00:00','<h1>Some content</h1>',
'My first post','Some excerpt','publish','closed', 'closed','','my-first-post',
'','','2014-08-28 02:00:00', '2014-08-28 00:00:00','',0,
'http://127.0.0.1/wordpress/?page_id=2000',0,'post','','')
请记住,您的表 wp_posts 可能有前缀。
【讨论】: