Code Fudging

The practice of fudging code in an unfamiliar language until it Just Works 
« Back to blog

Posting to Wordpress from Ruby using XMLRPC

There seems to be a dearth of resources for posting a new blog entry
to Wordpress via Ruby, and some confusion around which method needs to
be invoked. That method is metaWeblog.newPost:

 
require "xmlrpc/client" 
 
my_new_blog_post = { 
 :description => 'foo', 
 :title => 'Title of the Post', 
 :excerpt => 'ex', 
 :categories => ['Category1', 'Category2'] 
 :post_status => 'publish' 
 } 
 
server = XMLRPC::Client.new( blog[:url], blog[:path]) 
 
# Returns the ID of the new post, or fail 
resp = server.call("metaWeblog.newPost", 0, "username", "password", my_new_blog_post) 

Your categories array should contain the category names of the
categories on your blog, you can't just populate them with new ones.
You may also want to change the post_status to "draft" if you want to
review it before posting.

Comments (0)

Leave a comment...