0
    $content = array(
        'post_title' => $title,
        'post_content' => $body,
        'post_status' => 'publish', 
        'post_date' => $pub_date //What's the proper format for the date here?
    )

    $params = array(0,$this->settings['username'],$this->settings['password'],$content);
    $request = xmlrpc_encode_request('wp.newPost',$params);
    $this->Curl->post($this->controller->rpc_url,$request); 

我已经为 post_date 格式尝试了许多不同的变体,但都没有奏效。以下是我已经尝试过的所有组合,但它们都不起作用:

1) $pub_date = date('Y-m-d H:i:s', time());
2) $pub_date = time();
3) $pub_date = new IXR_Date(time());
4) $pub_date = date('c',time());
5) $datetime = new DateTime('2010-12-30 23:21:46');
   $pub_date = $datetime->format(DateTime::ISO8601);

似乎我测试了所有可能的解决方案,但每当我尝试包含 post_date 时它仍然不想发布。有人可以帮忙吗,我真的坚持这个。

4

2 回答 2

2

弄清楚了:

  $publish_date = '20121217T01:47:03Z' //this is the proper format for datetime 
  xmlrpc_set_type($publish_date, 'datetime'); //xmlrpc_set_type must be used on above date so that XML passes it properly as <dateTime.iso8601> instead of <string>

    $content = array(
        'post_title' => $title,
        'post_content' => $body,
        'post_status' => 'publish', 
        'post_date' => $publish_date);

    $params = array(0,$this->settings['username'],$this->settings['password'],$content);
    $request = xmlrpc_encode_request('wp.newPost',$params);
    $this->Curl->post($this->controller->rpc_url,$request); 
于 2012-12-17T20:18:17.373 回答
0

您可以使用 WordPresse Core 上提供的代码:

require '/ROOT/maaal/wp-includes/class-IXR.php';

$timestamp = time(); // Or some value you calculated somewhere
$xmlrpc_date = new IXR_Date($timestamp);

PS:$time 可以是 PHP 时间戳或 ISO 时间戳。

于 2014-01-01T17:37:16.430 回答