2012-12-17 20 views
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格式許多不同的變化,並沒有他們工作。這裏是所有的,我已經嘗試過的組合和他們都不工作:WordPress的XMLRPC(wp.newPost) - 無法獲得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。有人可以幫忙,我真的被困在這一個。

回答

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); 
0

您可以使用可用的代碼上WordPresse核心:

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

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

PS:$時間可以是一個PHP時間戳或ISO之一。