So, for those of you who read my last blog post, you might notice that I was having issues with a script I wrote to create a new post in Wordpress when it came time to upgrade the Wordpress code.  The SQL internals were modified, and I was inserting directly in to the database (yes, I know, I broke a cardinal rule).  I needed an alternative way to insert information in to the database that would be much more future-proof.  I remembered about XML-RPC.

It took me some time to find answers to questions I had about XML-RPC and the Wordpress’ API.  Wordpress comes with the ability to use XML-RPC, and AtomPub.  With regards to XML-RPC, it supports a few protocols:

  1. MetaWeblog
  2. Movable Type
  3. Blogger
  4. Wordpress’ own methods

Since there was little written documentation as to how to do this, I thought I’d share my findings.  Also, although the Blogger API was very easy to figure out and use, I’m not going to cover it here mainly because it doesn’t support the creation of a title field – something for my purposes were required.  (To access the blogger API, I used this class.)  I’m also only going to cover what’s necessary to create a new post for my own means, nothing more – hopefully it’ll get you on your way to how you’d like to use it.


Continue reading "Automatic Post Creation with Wordpress, PHP, and XML-RPC"

Wordpress Help: XML-RPC and the APIs

Thursday, February 5. 2009

So, I’m wondering if any of you Wordpress gurus out there have attempted to work with the XML-RPC and/or ATOM publishing APIs that Wordpress allows.  I realized, after updating Wordpress, that creating a script that manually inserted things in to Wordpress’ database was the wrong way to go about it when there’s a protocol I could access and use that would not be changed as Wordpress’ core files are changed.

I’ve had the hardest time trying to search through the docs to find proper formatting for these APIs however, and have little idea of where to begin to structure the request/response.  I know it would be much easier to use (especially the way Wordpress now uses the database with tags instead of categories), but I need that little extra push of knowledge!

Update: I got the Blogger API to work, but it didn’t support titles, something that was imperative for this project.  Ironically, neither Fiddler nor Ethereal packet sniffers helped me solve the problem of figuring out how Live Writer sent the data.  I still don’t know where some human readable RFCs can be found, but I’ve gotten the MetaWeblog API working – it’s just a simple array value (at least in PHP) that is sent to the method for content.  $content[‘title’] for the title, $content[‘description’] for the blog entry’s body text, and $content[‘categories’] is an array value that contains textual representation of the categor(y|ies) that you wish to use for the entry.  The publish (or draft) date and author are filled in automatically.

I still don’t know how to properly form the ATOM protocol (should HTML be wrapped/escaped?), or how it should be sent either; luckily I just needed something that would work.  The MetaWeblog API should suffice.

(Page 1 of 1, totaling 2 entries)