我想将自定义数据库中的类别和文章导入wordpress类别和帖子。任何想法,提示或代码片段都将非常受欢迎。
谢谢你和问候。
答案 0 :(得分:1)
基本上您需要做的是将您的记录插入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
可能有前缀。