views:

176

answers:

1

UPDATE (FIGURED OUT):

I figured this out on my own, this is not documented anywhere. The array reference passed needs to have each array item be a hash reference using either the a categoryName or categoryId key identifier. Meaning:

'categories' => [
  {'categoryName' => 'CatName1'},
  {'categoryName' => 'CatName2'},
],


The question below no longer needs answering...


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);
A: 

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