我已经使用api元博客成功地创建了新帖子。newPost。我可以在“所有帖子管理”页面下看到创建的新帖子。但问题是它不会显示在主页上。我只会在进入新帖子的编辑页面并单击更新后显示。是什么导致了这里的问题?
即使我使用wp\\u insert\\u post函数,上述情况也会发生。新帖子已成功创建,但不会显示在主页上。
它只有在我单击编辑帖子页面中的更新按钮后才会显示。(标题没有更新,内容还是一样。我所做的只是单击“更新”按钮)。
这是我使用的代码:
<?php
$BLOGURL = "http://xxxx/wordpress";
$USERNAME = "xxxx";
$PASSWORD = "xxxx";
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";
/*The contents of your post*/
$description = "This is a sample post.";
/*Forming the content of blog post*/
$content[\'title\'] = $title;
$content[\'description\'] = $description;
$content[\'categories\'] = array("mycategoryname");
/*Whether the post has to be published*/
$toPublish = true;
$request = xmlrpc_encode_request("metaWeblog.newPost",
array(1,$USERNAME, $PASSWORD, $content, $toPublish));
/*Making the request to wordpress XMLRPC of your blog*/
$xmlresponse = get_response($BLOGURL."/xmlrpc.php", $request);
$response = xmlrpc_decode($xmlresponse);
/*Printing the response on to the console*/
print_r($response);
echo "\\n";
?>