XMLRPC & MetaWeblog, how can i create a page, create a post, and attach the page to this post

841 Views Asked by At

I want to create my own custom posting interface for my Wordpress blog, my reason for this is because I post multiple articles, sometimes ranging from 100-150 articles per day, and I want to simplify the process of posting an article, like batch posting articles.

I did my research and I found that Wordpress XMLRPC and MetaWeblog API is what I need.

So I tried it and I successfully post an article to my blog using this code:

<?php
    include("../wp-includes/class-IXR.php");
    $client = new IXR_Client('http://www.example.com/xmlrpc.php');

    $content['title'] = 'Test Draft Entry using MetaWeblog API';
    $content['description'] = '<p>Hello World!</p>';
    if (!$client->query('metaWeblog.newPost','', 'admin',’password’, $content, false)) {
        die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
    }
    echo $client->getResponse();    
?>

But for each post that I create in my Wordpress blog requires several step:

Step 1: Create a new Background with a Background type of Youtube and enter the Youtube ID of this background.

enter image description here

Step 2: Add a new post and attach the previously published background to this post.

enter image description here

Step 3: Enter a custom field called artist_id in the custom field section and add an excerpt for this post, publish the post.

enter image description here

So, each article needs 3 steps. So my question is, how can I use the XMLRPC to perform these actions?

1

There are 1 best solutions below

1
On

For adding excerpts use

$content['mt_excerpt'] = 'Your post excerpt';

For custom fields use

$content['custom_fields'] = array(
    array( 'key' => 'artist_id', 'value' => '777' ),
    array( 'key' => 'background', 'value' => 'background_value' )
  );

Background and youtube metaboxes will most likely add custom post meta. You can find the key for them from db or source code and use it in above code.