开发者

Perl WordPress::XMLRPC categories not being set

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'],
    'des开发者_Go百科cription'       => '<p>Here is the content</p>',
    'mt_keywords'       => 'tag1, tag2, tag3',
    'mt_allow_comments' => 1,
};

my $ID = $o->newPost($hashref, 1);


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...


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜