Forums

[resolved] metaWeblog new post and adding custom fields (1 post)

  1. thelocutus
    Member
    Posted 2 years ago #

    Edit: Problem solved, if you're interested I've edited the code to include the changes I've made.

    Hello.

    I'm trying, without much success, to add a custom field to a post using the metaWeblog.newPost method.

    The post gets created successfully however the custom filed does not get created.

    I'd appreciate some help on the matter.

    <?php
    include("xmlrpc/lib/xmlrpc.inc"); // Make sure the XMLRPC library is in your path or give the full path
    
    $api_path = "http://localhost/xmlrpc.php";
    $username = "test";
    $password = "test";
    $charid = $_GET['id'];
    $charname = $_GET['name'];
    
    $c = new xmlrpc_client($api_path);
    //$c->debug = true; // Uncomment this line for debugging info
    
    $content['title'] = $charname;
    $content['categories'] = array("Category");
    
    // custom fields
    $content['custom_fields'] = array(array("key" => "import_id", "value" => $charid));
    
    $x = new xmlrpcmsg("metaWeblog.newPost",
            array(php_xmlrpc_encode("1"),
            php_xmlrpc_encode($username),
            php_xmlrpc_encode($password),
            php_xmlrpc_encode($content),
            php_xmlrpc_encode("1")));
    
    $c->return_type = 'phpvals';
    $r =$c->send($x);
    if ($r->errno=="0")
        echo "<br />Successfully Posted ";
    else {
        echo "<br />There was an error";
        print_r($r);
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags