wordpress,自动发布,从数据日期设置 post_date
我有 2,000 条数据想要导入到我的 wordpress 中,因为 wp 有很多运行良好的功能。我开始手动执行此操作,但后来意识到,编写脚本来导入它更容易。
一切都很完美!有一个问题,我无法让它使用我的数据的发布日期作为发布日期。
我花了 2 天的时间谷歌搜索并使用 SO 来获取资源,每个人都很接近,但有些答案使用了我不想做的 wp 内部编码结构。到目前为止,这是我所拥有的:
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
$content = array(
'title'=>$title,
'description'=>$body,
'mt_allow_comments'=>1, // 1 to allow comments
'mt_allow_pings'=>0, // 1 to allow trackbacks
'post_type'=>'post',
'post_status' => 'draft',
'publish' =>$pubdate,
'mt_keywords'=>$keywords,
'categories'=>array($category)
);
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
一切都很完美,但我无法确定工作日期。 RELEASEDATE 的格式与 WP、2011-03-04 14:33:21 等完全相同。
它在帖子上打印日期,但“发布”表示我运行脚本的日期。在上面的示例中,我将 RELEASEDATE 发送到 $pubdate。我知道 post_date 是一个对象,但不知道如何在这里实现它。
简而言之,如果我让这张纸条满载,我今天将收到 2,000 个帖子! :P
I have 2,000 pieces of data I want to import into my wordpress, as wp has many features that work nicely. I started doing it manually but then realized, that its easier to write a script to import it.
everything runs perfect!! one problem, I cannot get it to use the RELEASEDATE of my data as the POSTED date.
I have spend 2 days googling and using SO for resources, and everyone comes close, but some of the answers use wp inner coding structure which I do not want to do. Here is what I have so far:
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
$content = array(
'title'=>$title,
'description'=>$body,
'mt_allow_comments'=>1, // 1 to allow comments
'mt_allow_pings'=>0, // 1 to allow trackbacks
'post_type'=>'post',
'post_status' => 'draft',
'publish' =>$pubdate,
'mt_keywords'=>$keywords,
'categories'=>array($category)
);
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
That all works perfect but I cannot get the date to work. RELEASEDATE is formatted exactly like WP, 2011-03-04 14:33:21 etc.
It prints the date on the post, but the "posted" says the day i ran the script. in the above example I am sending RELEASEDATE to $pubdate. I know that the post_date is an object but not sure how to implement it here.
In short if i let this scrip run full I will have 2,000 post dated today!! :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此页面列出了metaWeblog.newPost接受的参数。
在该页面中,您可以使用“date_created_gmt”或“dateCreated”来存储日期数据。
This page list parameter accepted by metaWeblog.newPost.
From that page, you can use either 'date_created_gmt' or 'dateCreated' to store date data.
我这样做:
代码应该看起来像像这样:
对我来说,这就像一个魅力:-)
有关 ISO8601 和 XML 日期格式的更详细说明可以在此处找到:如何使用 XMLRPC / metaWeblog.newPost 安排帖子 ??
I do this in this way:
Code should looks like this:
For me this works like a charm :-)
More detailed description about ISO8601 and XML date format can be found here: How to scedule a Post using XMLRPC / metaWeblog.newPost ??