2012-02-10 59 views
3

我試圖通過XMLRPC添加多個類別到Wordpress(3.3.1)發佈。WordPress的帖子通過XMLRPC - 添加多個類別

這是我的代碼(它工作正常,請閱讀下文):

<? 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 


require_once("IXR_Library.php.inc"); // http://www.hurricanesoftwares.com/php_uploads/IXR_Library.txt 

$client->debug = true; //Set it to false in Production Environment 

$title="Blog Title5"; // $title variable will insert your blog title 
$body = "teste xmlrpc <a href='http://www.teste.com'>teste.com</a>"; 

$category="DVDSCR, Telesync"; // Comma seperated pre existing categories. Ensure that these categories exists in your blog. 
$keywords="keyword1, keyword2, keyword3"; 

$customfields=array('key'=>'Author-bio', 'value'=>'Autor Bio Here'); // Insert your custom values like this in Key, Value format 


    $title = htmlentities($title,ENT_NOQUOTES,$encoding); 
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding); 

    $content = array(
     'title'=>$title, 
     'description'=>$body, 
     'mt_allow_comments'=>0, // 1 to allow comments 
     'mt_allow_pings'=>0, // 1 to allow trackbacks 
     'post_type'=>'post', 
     'mt_keywords'=>$keywords, 
     'categories'=>array($category), 
     'custom_fields' => array($customfields) 


    ); 

// Create the client object 
$client = new IXR_Client('http://127.0.0.1/xmlrpc.php'); 

$username = "admin"; 
$password = "password"; 
$params = array(0,$username,$password,$content,true); // Last parameter is 'true' which means post immideately, to save as draft set it as 'false' 

// Run a query for PHP 
if (!$client->query('metaWeblog.newPost', $params)) { 
    die('Something went wrong - '.$client->getErrorCode().' : '.$client->getErrorMessage()); 
} 
else 
    echo "Article Posted Successfully"; 

?> 

錯誤:
如果我嘗試添加多個類別的職位類別設置爲未分類(默認)。

我已經試過這樣:

$category = "telesync, dvdscr"; 

這:

$category =array('telesync','dvdscr'); 

我怎麼能比一個類別更增加到帖子? 謝謝大家!

回答

2

我已經找到了答案測試一些其他選項,如後:

'categories'=>array("telesync", "1080p"), 

$內容變量應該是這樣的:

$content = array(
    'title'=>$title, 
    'description'=>$body, 
    'mt_allow_comments'=>0, // 1 to allow comments 
    'mt_allow_pings'=>0, // 1 to allow trackbacks 
    'post_type'=>'post', 
    'mt_keywords'=>$keywords, 
    'categories'=>array("telesync", "1080p"), // I've typed the categories directly here. 
    'custom_fields' => array($customfields) 


); 
0

我知道這是有點晚了,但對於遇到同樣問題的人,第一個猜測是最好的解決方案(而不是直接鍵入類別,最好將它們作爲變量傳遞):

$category =array('telesync','dvdscr'); 

我們只需要刪除'數組'就可以了categories=>array($category),因爲我們已經聲明$category爲一個數組。因此,而不是:

'categories'=>array($category), 

使用:

'categories'=>$category, 

,它應該工作。

相關問題