我坚持不懈地搜索和阅读,直到找到答案!事实证明,正确的使用方法实际上是MetaWeblog API和XMLRPC,您必须激活它们,因为它在默认情况下是禁用的。首先,访问管理面板中的设置菜单并导航到“写入”。向下滚动,直到在“远程发布”下看到XML-RPC复选框。一旦这是保存您的几乎所有设置。
您必须导出帖子,然后通读该xml文件,以获得特定自定义字段的元名称。以下是我使用的代码:
<?php
$BLOGURL = "your.wordpress.root/folder";
$USERNAME = "your_uesername";
$PASSWORD = "your_password";
function get_response($URL, $context) {
if(!function_exists(\'curl_init\')) {
die ("Curl PHP package not installed\\n");
}
/*Initializing CURL*/
$curlHandle = curl_init();
/*The URL to be downloaded is set*/
curl_setopt($curlHandle, CURLOPT_URL, $URL);
curl_setopt($curlHandle, CURLOPT_HEADER, false);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $context);
/*Now execute the CURL, download the URL specified*/
$response = curl_exec($curlHandle);
return $response;
}
/*Creating the metaWeblog.newPost request which takes on five parameters
blogid,
username,
password*/
/*The title of your post*/
$title = "Sample Post Title with Custom Fields";
/*The contents of your post*/
$description = "a collection lorem ipsums";
/*Forming the content of blog post*/
$content[\'title\'] = $title;
$content[\'description\'] = $description;
$content[\'categories\'] = array("Uncategorized");
/*Pass custom fields*/
$content[\'custom_fields\'] = array(
array( \'key\' => \'your_custom_feild_meta-key\', \'value\' => \'place whatever value your custom field requires here\' )
);
/*Whether the post has to be published, false means it will be created as a draft*/
$toPublish = false;
$request = xmlrpc_encode_request("metaWeblog.newPost",
array(1,$USERNAME, $PASSWORD, $content, $toPublish));
/*Making the request to wordpress XMLRPC of your blog, you may have to change this to the correct path for your xmlrpc.php file*/
$xmlresponse = get_response($BLOGURL."/xmlrpc.php", $request);
$response = xmlrpc_decode($xmlresponse);
/*Printing the response on to the console*/
/*If it works, you\'ll see a number followed by :Post ID*/
echo ":Post ID"; print_r($response);
echo "\\n";
?>
就是这样!现在,您可以使用一些php、javascript、perl。。。你想要什么都行!只有几个变量需要更改。