Perl WordPress::XMLRPC 类别未设置

发布于 2024-08-29 01:22:40 字数 897 浏览 3 评论 0原文

以下代码可以很好地将新帖子上传到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你爱我像她 2024-09-05 01:22:40

遇到了同样的问题,2小时后我找到了对我有用的解决方案:

my $id = $o->newPost(
    {
        title              => 'title',
        description        => 'description',
        categories         => [@tab],
        mt_keywords        => 'tag1, tag2, tag3',
        mt_allow_comments  => '1',
    },
    1   # Publish
);

似乎将 @tab 放在括号中会有所帮助,或者您可以按照下面的描述指定类别:

my $id = $o->newPost(
    {
        title              => 'title',
        description        => 'description',
        categories         => ['category1', 'category2'],
        mt_keywords        => 'tag1, tag2, tag3',
        mt_allow_comments  => '1',
    },
    1   # Publish
);

您有在发布之前创建类别:

$content_hashref->{name} = $elem;
$o->newCategory($content_hashref, 1);  # etc...

Had the same problem, after 2 hours I found the solution, which works for me:

my $id = $o->newPost(
    {
        title              => 'title',
        description        => 'description',
        categories         => [@tab],
        mt_keywords        => 'tag1, tag2, tag3',
        mt_allow_comments  => '1',
    },
    1   # Publish
);

It's seems that putting @tab in brackets helps or you can specify categories that way below as it has been described:

my $id = $o->newPost(
    {
        title              => 'title',
        description        => 'description',
        categories         => ['category1', 'category2'],
        mt_keywords        => 'tag1, tag2, tag3',
        mt_allow_comments  => '1',
    },
    1   # Publish
);

You have to create category before posting:

$content_hashref->{name} = $elem;
$o->newCategory($content_hashref, 1);  # etc...
煮茶煮酒煮时光 2024-09-05 01:22:40

我相信这是固定的,因为我执行以下操作没有问题(分割逗号分隔的列表 $categories):

my @categories = split(',', $categories);

my $id = $o->newPost(
 {
      title           => 'title',
        description   => 'description',
        categories    => \@categories,
        mt_keywords      => 'tag1, tag2, tag3',
        mt_allow_comments  => '1',
     },
     0 # Publish?
    );

I believe this is fixed, as I had no problem doing the following (splitting a comma separated list $categories):

my @categories = split(',', $categories);

my $id = $o->newPost(
 {
      title           => 'title',
        description   => 'description',
        categories    => \@categories,
        mt_keywords      => 'tag1, tag2, tag3',
        mt_allow_comments  => '1',
     },
     0 # Publish?
    );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文