• Hello,
    I am using the WP 2.9 and i need to use XML RPC Feature in WP to posts the Blog Post
    When i use PHP and XML RPC it does not works

    I have enabled the XML RPC feature in WP and here is the PHP Code i used

    Can some one say how can i fix this??

    <?php
        $username = "testuser";
        $password = "itestpaass";
        $rpurl = "https://domain.com/xmlrpc.php";
        $categories = "info";
        $title = "We want a test post";
        $categories = "Test";
        $body = "This is the body of the post"
    
    function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1))
    {
    
        $params = array('','',$username,$password,1);
        $request = xmlrpc_encode_request('blogger.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);
        curl_exec($ch);
        curl_close($ch);
    
    };
    
    ?>

    Thanks in advance!

Viewing 8 replies - 1 through 8 (of 8 total)
  • What sort of error gets returned? Did you look at the raw XML your script is sending to verify that it looks right?

    Have you considered using the IXR library for XML-RPC calls? It ships with WP (it is in wp-includes/class-IXR.php).

    Thread Starter jhbalaji

    (@jhbalaji)

    Joseph i mailed you from your Blog

    Also can i get more details about the IR Library

    thanks ??

    Thread Starter jhbalaji

    (@jhbalaji)

    The problem seems to be from my Host, DreamHost those Guys refuse to activate XML extension in php.ini and bluffing other things!
    Even i followed their Wiki But it did not worked for me even after following them
    But it works fine from my localhost using XAMPP

    Any alternative suggestion!
    Thanks any way! ??

    Thread Starter jhbalaji

    (@jhbalaji)

    Ooops!! Even in localhost its not working now!
    I am in need of your help!

    You’ll need to provide more information, like what exactly the HTTP response was to the XML-RPC request.

    <?php

    function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$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,
    ‘mt_allow_pings’=>0,
    ‘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;
    }

    $title = ‘test’;
    $body = ‘test’;
    $rpcurl = ‘https://address/xmlrpc.php&#8217;;
    $username = ‘test’;
    $password = ‘test’;
    $category = ‘test’;

    $chk = wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords=”,$encoding=’UTF-8′);

    if($chk){
    echo $chk;
    }else{
    echo ‘failed’;
    }

    ?>

    You should try this one..

    I prefer using a direct connection to the database with a destop script:
    https://askblogautomation.com/blog/create-a-new-wordpress-post-programmatically/

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘XML RPC and PHP’ is closed to new replies.