How to post to Wordpress or Joomla via cURL?

by brentb
2 replies
I would like to find out how to post to a wordpress or joomla install via cURL in php....

I want to do this remotely on a different server.

So you would need to send the admin and password log in as well as other data to fill out the form and submit.

Can someone please help me out? I find code around but I can't figure out whats going on because its sloppy or because its not exactly the right thing...

Or an easy to follow clear tutorial on connecting to sites via cURL would also be useful....

Thanks!
#curl #joomla #post #wordpress
  • Profile picture of the author linux2aix
    Here is the function. This code is not made for being used within WordPress, so don't paste it on your functions.php file (or any other).

    Please note that you must activate the XMLRPC posting option in your WordPress blog. If this option isn't activated, the code will not be able to insert anything into your blog database. Another thing, make sure the XMLRPC functions are activated on your php.ini file.

    function wpPostXMLRPC($title,$body,$rpcurl,$username,$passw ord,$category,$keywords='',$encoding='UTF-8') {
    $title = htmlentities($title,ENT_NOQUOTES,$encoding);
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);

    $content = array(
    'title'=>$title,
    'description'=>$body,
    'mt_allow_comments'=>0, // 1 to allow comments
    'mt_allow_pings'=>0, // 1 to allow trackbacks
    'post_type'=>'post',
    'mt_keywords'=>$keywords,
    'categories'=>array($category)
    );
    $params = array(0,$username,$password,$content,true);
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_URL, $rpcurl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    $results = curl_exec($ch);
    curl_close($ch);
    return $results;
    ?>
    {{ DiscussionBoard.errors[4848175].message }}
    • Profile picture of the author indiawebdevelop
      Originally Posted by linux2aix View Post

      Here is the function. This code is not made for being used within WordPress, so don't paste it on your functions.php file (or any other).

      Please note that you must activate the XMLRPC posting option in your WordPress blog. If this option isn't activated, the code will not be able to insert anything into your blog database. Another thing, make sure the XMLRPC functions are activated on your php.ini file.

      function wpPostXMLRPC(,,,,,,='',='UTF-8') {
      = htmlentities(,ENT_NOQUOTES,);
      = htmlentities(,ENT_NOQUOTES,);

      = array(
      'title'=>,
      'description'=>,
      'mt_allow_comments'=>0, // 1 to allow comments
      'mt_allow_pings'=>0, // 1 to allow trackbacks
      'post_type'=>'post',
      'mt_keywords'=>,
      'categories'=>array()
      );
      = array(0,,,,true);
      = xmlrpc_encode_request('metaWeblog.newPost',);
      = curl_init();
      curl_setopt(, CURLOPT_POSTFIELDS, );
      curl_setopt(, CURLOPT_URL, );
      curl_setopt(, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt(, CURLOPT_TIMEOUT, 1);
      = curl_exec();
      curl_close();
      return ;
      ?>
      Nice work and I have just used the given code from you and really awesome.
      {{ DiscussionBoard.errors[6005260].message }}

Trending Topics