wordpress metaWeblog.newPost xmlrpc create category if not exist, and prevent duplicate titles from codeigniter

I’m using codeigniter to post to my wordpress blog.

code

Read More

model

function doPost($title='new post',$content='hi',$categories=array('new'),$keys='new, none')
    {
        $this->load->library('xmlrpc');

        $thePost= array(
            array(
                'title' => array($title,'string'),
                'date_created_gmt'=>array($datetime,'dateTime.iso8601'),
                'description' => array($content,'string'),
                'categories' => array($categories,'struct'),
                'mt_keywords'    => array($keys,'string'),
                'post_type' => array('post','string'),
            ),
            'struct'
        );
        $this->xmlrpc->server('http://demo.com/xmlrpc.php', 80);
        $this->xmlrpc->method('metaWeblog.newPost');
        $request = array('1',$user,$pass,$thePost,TRUE);
        $this->xmlrpc->request($request);
        $result = $this->xmlrpc->send_request();

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

but i have a question.

1st. can i check if there a post already exist with same title ?

2nd. currently if i post a category that is not there, post is submited as uncategorised,
how can i alter this to create category if not exists ??

3rd. Can i post multiple posts in one xmlrpc request ?

thanks, i’m using latest version of wordpress (today is day0 for me with wordpress !) and its located on remote server..

thanks thanks

Related posts

Leave a Reply

1 comment

  1. Re- 1st / 2nd.

    You can use wp.getTerms to check if category exists.

    Add the category using wp.newTerm

    Create a post using wp.newPost

    Re- 3rd.

    Can I post multiple posts in one xmlrpc request ?

    No, not to push in content.

    Nonetheless if you do have access to the WP installation you can create a small plugin that would pull content from a feed and insert_posts after a remote trigger from your CI application.