• Resolved badskills

    (@badskills)


    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">
    <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>

    All this code is working but not posting in given category,

    Is there anyone who can add all features to of metaWeblog.newPost in this example ?

    you can find supported features in XMLRPC.php file in this function.

    function mw_newPost($args)
    
    // We've got all the data -- post it:
    		$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input', 'page_template');

    Thanks for help

Viewing 1 replies (of 1 total)
  • Thread Starter badskills

    (@badskills)

    okay i just figured it out

    $content['categories'] = $_POST['category'];
    
    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

Viewing 1 replies (of 1 total)
  • The topic ‘How to use metaWeblog.newPost (xmlrpc api) properly with PHP ?’ is closed to new replies.