Welcome Guest, Not a member yet? Register   Sign In
Need a code sample showing how to post to Wordpress using Codeigniter.
#1

[eluser]squelly[/eluser]
Does anyone have a code sample they can share that show how to make a basic blog post to Wordpress using the CodeIgniter xml-rpc library?

So far, I have this, which always results in "Bad login/pass combination", although I am using the correct combination.

Code:
function doPost(){

        $this->load->library('xmlrpc');

        $bloguser = "theUserid";
        $blogpass = "thePassword";
        $blogid = 0; //I've tried 0 and 1 here.
        $post['title'] = "The title of a new post";
        $post['description'] = "The body of the post.";
        $this->xmlrpc->server("http://localhost/blog/xmlrpc.php", 80);
        $this->xmlrpc->method('metaWeblog.newPost');

        $this->xmlrpc->request = array($blogid, $bloguser, $blogpass, $post, TRUE);
        if ( ! $this->xmlrpc->send_request())
        {
                echo $this->xmlrpc->display_error();
        }
        else
        {
                echo '<pre>';
                print_r($this->xmlrpc->display_response());
                echo '</pre>';
        }
}
#2

[eluser]Dam1an[/eluser]
Have you enabled XML-RPC under remote publishing in settings > writting?
I didn't know about that and wondered why I was getting a login error for ages
#3

[eluser]squelly[/eluser]
Yes, I have, good thought tho' !
#4

[eluser]squelly[/eluser]
After much gnashing of teeth, this seems to work:

Code:
function doPost(){
        
        $this->load->library('xmlrpc');
    
        $bloguser = "theUserID";
        $blogpass = "thePassword";
        $blogid = 1;
        $publishImmediately = TRUE;

        $thePost = array(array('title'  => array('this is the title','string'),
                                'description'    => array('this is the description','string')
                                ),
                         'struct');              
        

        $myPost = "my post";
        //$this->xmlrpc->set_debug(TRUE);
        $this->xmlrpc->server("http://url.to/xmlrpc.php", 80);
        $this->xmlrpc->method('metaWeblog.newPost');

        $request = array($blogid, $bloguser, $blogpass, $thePost, $publishImmediately);
        
        $this->xmlrpc->request($request);
        $result = $this->xmlrpc->send_request();

        if ( !$result )
        {
            echo $this->xmlrpc->display_error();
        }
        else
        {
            echo '<pre>';
            print_r($this->xmlrpc->display_response());
            echo '</pre>';
        }
    }

The important part is to note the struct for the elements of the actual post.




Theme © iAndrew 2016 - Forum software by © MyBB