views:

385

answers:

1

Update: solved this problem see answer

I want to make new posts on my blog remotely with XMLRPC api and i m trying to use metaWeblog.newPost function, because it provides much features. I successfully added new posts into wordpress but i failed to post it in a defined category(categories)

i tried lots of various things but failed at end now i m using code from this site http://www.samuelfolkes.com/2009/08/posting-to-wordpress-with-php-and-xml-rpc/

after stripping down the code for my needs here's what i got and its working fine

remotepost.class.php

<?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 ( you can name it whatever you want )

<?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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<title>WordPress Poster</title>
</head>
<body>
<?php
if(isset($_POST['submit'])) echo "Posted! <a href=\"http://localhost/wp/?p=$pid\"&gt;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>

dont know whats wrong in this code :( ,failing to post in right directory

A: 
include "remotepost.class.php";
$content['title'] = $_POST['title'];
$content['categories'] = $_POST['category'];
$content['description'] = $_POST['description'];

changes to

$content['categories'] = array($_POST['category']); 

It must be an array, it took my all night, i guess i have read more than 200 pages for this lol, gooooogled

Sjne