[wp-xmlrpc] multiple custom fields using metaweblog.newPost

x-wp-xml at chaj.com x-wp-xml at chaj.com
Sat Aug 29 22:56:08 UTC 2009


Help, I'm trying to create a new post with custom fields using the following 
perl script, but there seems to be an issue with the custom fields, only the 
second one "width" ever seems to get posted. Can't make multiple fields go up. 
When I add another field, I get the "Odd number of elements in anonymous hash" 
error. This has got to be something simple - would someone kindly sanity check 
my syntax? Thanks.

#!/usr/bin/perl -w
use strict;
use RPC::XML::Client;
use Data::Dumper;

my $cli=RPC::XML::Client->new('http://www.sitename.com/wp/xmlrpc.php');

my $appkey="perl"; # doesn't matter
my $blogid=1; # doesn't matter (except blogfarm)

my $username="Jim";
my $passwd='_____';

my $text=<<'END';

This is the post content...

You can also include html tags...

See you!
END

my $publish=0; # set to 1 to publish, 0 to put post in drafts

my $resp=$cli->send_request('metaWeblog.newPost',
   $blogid,
   $username,
   $passwd,
   {
     'title'       => "this is doodoo",
     'description' => $text,
     'custom_fields' => {
       { "key" => "height", "value" => 500 },
       { "key" => "width", "value" => 750 }
     },
   },
   $publish);

exit 0;


More information about the wp-xmlrpc mailing list