Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use XML-RPC metaWeblog.newPost properly with PHP?
    primarykey
    data
    text
    <p>I want to make new posts on my blog remotely with XMLRPC API and I'm trying to use <code>metaWeblog.newPost</code> function, because it provides more features. I successfully added new posts into WordPress but failed to post it in a defined category.</p> <p>I tried lots of various things but failed. Now I'm using code from <a href="http://www.samuelfolkes.com/2009/08/posting-to-wordpress-with-php-and-xml-rpc/" rel="nofollow noreferrer">this site</a>, after stripping down the code for my needs here's what I got and it's working fine:</p> <p><strong>remotepost.class.php</strong></p> <pre><code>&lt;?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-&gt;ixrPath; $this-&gt;client = new IXR_Client($this-&gt;wpURL); $this-&gt;postID = $this-&gt;postContent($content); } private function postContent($content) { $content['description'] = $content['description']; if(!$this-&gt;client-&gt;query('metaWeblog.newPost','',$this-&gt;uname,$this-&gt;pass,$content,true)) throw new Exception($this-&gt;client-&gt;getErrorMessage()); return $this-&gt;client-&gt;getResponse(); } } ?&gt; </code></pre> <p><strong>post.php</strong> ( you can name it whatever you want )</p> <pre><code>&lt;?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-&gt;postID; } catch(Exception $e) { echo $e-&gt;getMessage(); } } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;WordPress Poster&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php if(isset($_POST['submit'])) echo "Posted! &lt;a href=\"http://localhost/wp/?p=$pid\"&gt;View Post&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;"; ?&gt; &lt;form enctype="multipart/form-data" method="post" action="#"&gt; Title &lt;input type="text" name="title" /&gt; &lt;br /&gt; Category &lt;input type="text" name="category" /&gt; &lt;br /&gt; Description &lt;input type="text" name="description" /&gt; &lt;br /&gt; &lt;input type="submit" value="Submit" name="submit" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Why this code fails to post in right directory (categories)?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload