首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确使用XML metaWeblog.newPost?

如何正确使用XML metaWeblog.newPost?
EN

Stack Overflow用户
提问于 2010-04-22 23:52:48
回答 1查看 4.1K关注 0票数 1

我想用XMLRPC远程在我的博客上发表新的文章,我正在尝试使用metaWeblog.newPost函数,因为它提供了更多的特性。我成功地在WordPress中添加了新的帖子,但未能在定义的类别中发布。

我尝试了很多不同的事情,但都失败了。现在,我正在使用本站的代码,在为我的需要剥离代码之后--这是我得到的--它运行得很好:

remotepost.class.php

代码语言:javascript
复制
<?php
class remotePost
{
    private $client;
    private $wpURL = 'http://localhost/wp/xmlrpc.php ';
    private $ixrPath = '/wp-includes/class-IXR.php';
    private $uname = 'zxc';
    private $pass = 'zxc';
    public $postID;
    function __construct($content)
    {
        if(!is_array($content)) throw new Exception('Invalid Argument');
        include $this->ixrPath;
        $this->client = new IXR_Client($this->wpURL);

        $this->postID = $this->postContent($content);
    }
    private function postContent($content)
    {
        $content['description'] =  $content['description'];
        if(!$this->client->query('metaWeblog.newPost','',$this->uname,$this->pass,$content,true)) throw new Exception($this->client->getErrorMessage());
        return $this->client->getResponse();
    }
}
?>

post.php (您可以随意命名它)

代码语言:javascript
复制
<?php
if(isset($_POST['submit']))
{
    include "remotepost.class.php";
    $content['title'] = $_POST['title'];
    $content['categories'] = $_POST['category'];
    $content['description'] = $_POST['description'];
    try
    {
        $posted = new remotePost($content);
        $pid = $posted->postID;
    }
    catch(Exception $e)
    {
        echo $e->getMessage();
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>WordPress Poster</title>
</head>
<body>
<?php
    if(isset($_POST['submit']))
        echo "Posted! <a href=\"http://localhost/wp/?p=$pid\">View Post</a><br /><br />";
?>
    <form enctype="multipart/form-data" method="post" action="#">
        Title <input type="text" name="title" /> <br />
        Category <input type="text" name="category" /> <br />
        Description <input type="text" name="description" /> <br />
        <input type="submit" value="Submit" name="submit" />
    </form>
</body>
</html>

为什么这段代码无法在正确的目录(类别)中发布?

EN

回答 1

Stack Overflow用户

发布于 2010-04-23 00:10:52

代码语言:javascript
复制
include "remotepost.class.php";
$content['title'] = $_POST['title'];
$content['categories'] = $_POST['category'];
$content['description'] = $_POST['description'];

更改为

代码语言:javascript
复制
$content['categories'] = array($_POST['category']); 

它一定是一个数组,花了我一整晚的时间,我想我已经读了200多页了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2695323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档