Php 使用wordpress API向新的wordpress帖子添加自定义字段

Php 使用wordpress API向新的wordpress帖子添加自定义字段,php,wordpress,api,Php,Wordpress,Api,我需要以编程方式创建新的Wordpress帖子,并为每个帖子分配自定义字段。使用Wordpress xmlrpc API,我可以成功地添加一篇新文章,但是自定义字段没有添加 下面是代码的摘录: $blogid = 0; $username = 'user'; $password = 'xyzzy1234'; $method = 'wp.newPost'; $title = "Post Title"; $pcontent = "I'm the post content."; $categories

我需要以编程方式创建新的Wordpress帖子,并为每个帖子分配自定义字段。使用Wordpress xmlrpc API,我可以成功地添加一篇新文章,但是自定义字段没有添加

下面是代码的摘录:

$blogid = 0;
$username = 'user';
$password = 'xyzzy1234';
$method = 'wp.newPost';
$title = "Post Title";
$pcontent = "I'm the post content.";
$categories = array('Cat 1', 'Cat 2');
$post_status = 'publish';  
$custom_fields = array('cccId' => '12345', 'cccType' => 'news');
$content = array(
                'post_type' => 'post',
                'post_status' => $post_status,
                'post_title' => $title,
                'post_content' => $pcontent,
                'terms_names' => array('category'=>$categories),
                'comment_status' => $comment_status,
                'ping_status' => $ping_status,
                'custom_fields' => $custom_fields
            );

$parameters = array($blogid, $username, $password, $content);
$response = sendRequest($method, $parameters);

function sendRequest($methodName, $parameters)  {
$request = xmlrpc_encode_request($methodName, $parameters);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, RPC_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
$results = print_r(xmlrpc_decode($results));
curl_close($ch);
return $results;
}

经过一些实验,结果表明$custom_字段需要如下指定:

$custom_fields = array(
                   array('key' => 'cccId', 'value' => '12345'),
                   array('key' => 'cccType', 'value' => 'news')
                 );

经过一些实验,结果表明$custom_字段需要如下指定:

$custom_fields = array(
                   array('key' => 'cccId', 'value' => '12345'),
                   array('key' => 'cccType', 'value' => 'news')
                 );

非常感谢。找不到任何关于这个的准确文档,直到我找到这个,我的头才被撞伤。谢谢!找不到任何关于这个的准确文件,直到我找到这个,我的头都被撞到了。