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.
One thing to note: In order for this to work, your version of Wordpress will have to have “Remote Publishing” enabled; depending on which protocol(s) you’ll be using, you’ll want to enable either “Atom Publishing Protocol” or “XML-RPC”, or both. This can be found (as of Wordpress version 2.7) under “Settings” and then “Writing”.