Wordpress XML-RPC和特色图像 [英] Wordpress XML-RPC and featured images

查看:349
本文介绍了Wordpress XML-RPC和特色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为一个客户端开发一个插件,每小时需要一个xml feed并将其发布到wordpress中,但我无法将精选图片发送到帖子。

I'm currently developing a plugin for a client that takes an xml feed hourly and posts it into wordpress and I'm having trouble sending the featured image to the post.

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

I can post to wordpress fine but all my attempts to post the featured image have failed.

<?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补丁票,但可以'似乎弄清楚如何实际使用新功能

Is what i currently have, i've been reading the wordpress patch tickets on this issue but can't seem to figure out how to actually use the new features

谢谢

推荐答案

它应该是这样的

   'wp_post_thumbnail' => $pictureid

您必须将上传图片的ID转换为变量,然后将其指定为值'metaWeblog.newPost'的'wp_post_thumbnail'参数

You have to get the ID of uploaded picture into variable and then assign it as a value of 'wp_post_thumbnail' parameter for 'metaWeblog.newPost'

这篇关于Wordpress XML-RPC和特色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆