Perl WordPress::XMLRPC 类别未设置
以下代码可以很好地将新帖子上传到 WordPress 博客,但对于我来说,我似乎无法设置类别。
类别是存在的。我尝试过所有小写,尝试过大小写匹配,尝试过 slug 版本。什么都不起作用。无论我如何尝试传递类别,该帖子都只会分配给默认类别。
我在网上搜索了其他示例代码,但没有提到如何使用 WordPress::XMLRPC 模块。
use WordPress::XMLRPC;
my $o = WordPress::XMLRPC->new;
$o->username('username');
$o->password('password');
$o->proxy('http://blogdomain.com/xmlrpc.php');
$o->server() || die "$!";
my $hashref = {
'title' => 'Test New Post 999 555456782',
'categories' => ['Categorie1', 'Categorie2'],
'description' => '<p>Here is the content</p>',
'mt_keywords' => 'tag1, tag2, tag3',
'mt_allow_comments' => 1,
};
my $ID = $o->newPost($hashref, 1);
The following code works fine to upload a new post to a WordPress blog but for the life of me I can't seem to get the categories to be set.
The categories exist. I've tried all lower case, tried case-matching, tried the slug version. Nothing works. No matter how I try passing the categories, the post gets assigned only to the default category.
I've scoured the web to find other pieces of sample code and none mention the actual code semantics of how to assign post to certain categories using the WordPress::XMLRPC module.
use WordPress::XMLRPC;
my $o = WordPress::XMLRPC->new;
$o->username('username');
$o->password('password');
$o->proxy('http://blogdomain.com/xmlrpc.php');
$o->server() || die "$!";
my $hashref = {
'title' => 'Test New Post 999 555456782',
'categories' => ['Categorie1', 'Categorie2'],
'description' => '<p>Here is the content</p>',
'mt_keywords' => 'tag1, tag2, tag3',
'mt_allow_comments' => 1,
};
my $ID = $o->newPost($hashref, 1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
遇到了同样的问题,2小时后我找到了对我有用的解决方案:
似乎将
@tab
放在括号中会有所帮助,或者您可以按照下面的描述指定类别:您有在发布之前创建类别:
Had the same problem, after 2 hours I found the solution, which works for me:
It's seems that putting
@tab
in brackets helps or you can specify categories that way below as it has been described:You have to create category before posting:
我相信这是固定的,因为我执行以下操作没有问题(分割逗号分隔的列表 $categories):
I believe this is fixed, as I had no problem doing the following (splitting a comma separated list $categories):