【问题标题】:Wordpress XML-RPC and featured imagesWordpress XML-RPC 和特色图片
【发布时间】:2012-11-02 21:53:07
【问题描述】:

我目前正在为客户端开发一个插件,该插件每小时接收一个 xml 提要并将其发布到 wordpress 中,但我无法将特色图片发送到帖子。

我可以很好地发布到 wordpress,但我发布特色图片的所有尝试都失败了。

<?php
class XMLRPClientWordPress
{
var $XMLRPCURL = "";
var $UserName  = "";
var $PassWord = "";
// Constructor
public function __construct($xmlrpcurl, $username, $password)
{
$this->XMLRPCURL = $xmlrpcurl;
$this->UserName  = $username;
$this->PassWord = $password;
}
function send_request($requestname, $params)
{
$request = xmlrpc_encode_request($requestname, $params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $this->XMLRPCURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
}
public function create_post( $title, $body )
{
$title = htmlentities( $title, ENT_NOQUOTES, 'UTF-8' );
$content = array(
    'post_category' => array( 18 ), // my category id
    'post_type' => 'post',
    'post_title' => $title,
    'post_content' => $body,
    'featured_image_url' => 'http://www.geekologie.com/2009/02/18/scary%20clown.jpg',
);

$params = array( 0, $this->UserName, $this->PassWord, $content );
return $this->send_request( 'wp.newPost', $params );
}
}
$objXMLRPClientWordPress = new XMLRPClientWordPress("xxxx/xmlrpc.php" , "xxxxx" , "xxxx");
$objXMLRPClientWordPress->create_post('Hey Chloe','Hope you like the clown'); 
?>

是我目前拥有的,我一直在阅读有关此问题的 wordpress 补丁票,但似乎无法弄清楚如何实际使用新功能

谢谢

【问题讨论】:

    标签: wordpress image rpc xml-rpc


    【解决方案1】:

    应该是这样的

       'wp_post_thumbnail' => $pictureid
    

    您必须将上传图片的 ID 获取到变量中,然后将其分配为 'metaWeblog.newPost' 的 'wp_post_thumbnail' 参数的值

    【讨论】:

      猜你喜欢
      • 2012-09-03
      • 2011-05-21
      • 2019-07-31
      • 2015-04-28
      • 2016-08-14
      • 2015-07-17
      • 2014-05-13
      • 2014-11-22
      • 2015-04-12
      相关资源
      最近更新 更多