Wordpress Post Via XMLRPC-添加多个类别


Wordpress Post Via XMLRPC - Add Multiple Categories

我正试图通过XMLRPC将多个类别添加到Wordpress(3.3.1)文章中。

这是我的代码(工作正常,请阅读以下内容):

<?
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');

如何在帖子中添加多个类别?谢谢大家!

我在测试了一些其他选项后找到了答案,比如:

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

$content变量如下所示:

$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)

);

我知道这有点晚了,但对于那些遇到同样问题的人来说,第一个猜测是最好的解决方案(与其直接键入类别,不如将它们作为变量传递):

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

我们只需要删除categories=>array($category)上的"array",因为我们已经将$category声明为数组。所以不是:

'categories'=>array($category),

用途:

'categories'=>$category,

它应该起作用。