采用metaWeblog.newPost而不是Weblog.newPost方法,支持添加Custom Fields字段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function post($result){
include("xmlrpc.inc");
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
$c = new xmlrpc_client("xmlrpc.php","example.com", 80);
$content['title']="title";
$content['description']="content";
$content['mt_keywords']="tag1,tag2";
$content['wp_password']="";
$content['categories'] = array("label");
$content['custom_fields'] = array(
array( 'key' => 'city', 'value' => 'Sacramento' )
);
$x = new xmlrpcmsg("metaWeblog.newPost",
array(php_xmlrpc_encode("1"),
php_xmlrpc_encode("admin"),
php_xmlrpc_encode('123456'),
php_xmlrpc_encode($content),
php_xmlrpc_encode("1")));

$c->return_type = 'phpvals';
$r =$c->send($x);
if ($r->errno=="0")
echo "success,ID:".$r->val;
else {
echo "fail";;
print_r($r);
}
}