【问题标题】:Perl WordPress::XMLRPC categories not being setPerl WordPress::XMLRPC 类别未设置
【发布时间】:2011-02-07 08:41:00
【问题描述】:

以下代码可以很好地将新帖子上传到 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);

【问题讨论】:

    标签: perl wordpress xml-rpc


    【解决方案1】:

    遇到同样的问题,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...
    

    【讨论】:

      【解决方案2】:

      我相信这已解决,因为我在执行以下操作时没有问题(拆分逗号分隔的列表 $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?
          );
      

      【讨论】:

        猜你喜欢
        • 2016-08-01
        • 2012-03-02
        • 2010-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多