gpt4 book ai didi

php - Wordpress 通过 XMLRPC 发布 - 添加多个类别

转载 作者:搜寻专家 更新时间:2023-10-31 21:15:44 26 4
gpt4 key购买 nike

我正在尝试通过 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)


);

关于php - Wordpress 通过 XMLRPC 发布 - 添加多个类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9221859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com