Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress,自动投递,从数据日期设置投递日期_Wordpress_Date - Fatal编程技术网

wordpress,自动投递,从数据日期设置投递日期

wordpress,自动投递,从数据日期设置投递日期,wordpress,date,Wordpress,Date,我有2000条数据要导入我的wordpress,因为wp有很多功能可以很好地工作。我开始手动操作,但后来意识到,编写脚本导入它更容易 一切都很完美!!一个问题是,我不能让它使用我的数据发布日期作为发布日期 我花了两天时间在谷歌上搜索并使用SO获取资源,每个人都很接近,但有些答案使用了wp内部编码结构,这是我不想做的。以下是我到目前为止的情况: $title = htmlentities($title,ENT_NOQUOTES,$encoding); $keywords

我有2000条数据要导入我的wordpress,因为wp有很多功能可以很好地工作。我开始手动操作,但后来意识到,编写脚本导入它更容易

一切都很完美!!一个问题是,我不能让它使用我的数据发布日期作为发布日期

我花了两天时间在谷歌上搜索并使用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(); 
这一切都很完美,但我无法确定开始工作的日期。发布日期的格式与WP,2011-03-04 14:33:21等完全相同

它在帖子上打印日期,但“发布”写的是我运行脚本的那天。在上面的示例中,我将RELEASEDATE发送到$pubdate。我知道post_日期是一个对象,但不确定如何在这里实现它

简言之,如果我让这张纸条满了,我今天就有2000张过期票了!!:P

列出metaWeblog.newPost接受的参数

在该页面中,您可以使用“date\u created\u gmt”或“dateCreated”来存储日期数据。

我是这样做的:

  • 使用
  • 代码应该如下所示:

    $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();
    
  • 对我来说,这就像一个符咒:-)


    关于ISO8601和XML日期格式的更详细描述可以在这里找到:

    'dateCreated'=>$pubdate',date\u created\u gmt'=>$pubdate,我在上面的脚本中添加了这一点,现在它不发布任何信息。我做得不对吗?好吧,把它改成:'dateCreated'=>date(date_ISO8601,strotime($pubdate)),现在它发布了,但是你猜怎么着,回到我原来的问题上,仍然使用今天的发布日期而不是pubdate。其他人都尝试一下。如果日期格式错误,则不会发布。如果日期格式为coorect,则它始终默认为今天的日期,而不是我的数据日期。