当您尝试手动制作帖子时,例如:example。com/wp-admin/post-new。php?p={postid}已设置。
我试图做的是在尝试使用xmlrpc创建新帖子时获取{postid},这可能吗?
这是我正在使用的代码。我可以在写了一篇新文章后获得postID,但我无法获得{postID}。我想把它放在$pcontent上。
Update: I really can\'t get the postID it echo automatically when your code executed sucessfully
<?php
$blogid = 0;
$username = \'admin\';
$password = \'123\';
$method = \'wp.newPost\';
$title = "TEST";
$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\' => $blogid,
\'terms_names\' => array(\'category\'=>$categories),
\'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, "localhost/wp/xmlrpc.php");
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;
}
// After the code executed successfully I can get the postID by echo $blog_id which return the postID correctly ;
// If I try to put it inside the code it returns 0;
?>