wordpress,自动发布,从数据日期设置 post_date

发布于 2024-11-10 11:06:05 字数 1250 浏览 0 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昵称有卵用 2024-11-17 11:06:05

此页面列出了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.

忘羡 2024-11-17 11:06:05

我这样做:

  1. 使用 Incutio XML-RPC PHP 库
  2. 代码应该看起来像像这样:

    $client = new IXR_Client('http://wp-blog.com/xmlrpc.php');
    
    $帖子=数组(
        'post_type'=>; '邮政',
        '标题' => $标题,
        '描述' => $描述,
        'date_created_gmt' =>;新的 IXR_Date(时间()),
    );
    
    if (!$client->query('metaWeblog.newPost', '', $login, $password, $post, true))
    {
        die( '创建新帖子时出错' . $client->getErrorCode() ." : ". $client->getErrorMessage());
    }
    
    $post_id = $client->getResponse();
    

对我来说,这就像一个魅力:-)

有关 ISO8601 和 XML 日期格式的更详细说明可以在此处找到:如何使用 XMLRPC / metaWeblog.newPost 安排帖子 ??

I do this in this way:

  1. Use the Incutio XML-RPC Library for PHP
  2. Code should looks like this:

    $client = new IXR_Client('http://wp-blog.com/xmlrpc.php');
    
    $post = array(
        'post_type'=> 'post',
        'title' => $title,
        'description' => $description,
        'date_created_gmt' => new IXR_Date(time()),
    );
    
    if (!$client->query('metaWeblog.newPost', '', $login, $password, $post, true))
    {
        die( 'Error while creating a new post' . $client->getErrorCode() ." : ". $client->getErrorMessage());
    }
    
    $post_id = $client->getResponse();
    

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 ??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文