Post to WordPress With iKnode

We are avid users of Wordpress. I have been using Wordpress as the Blog engine in my personal blog for years now. I really like the platform. Recently we have been helping several of our users integrate iKnode with Wordpress, specially for inserting Blog posts automatically. So we have built an wrapper to make it easy for iKnode apps to automatically insert posts into an existing wordpress blog.

Setting up Wordpress.

Wordpress uses the XML RPC protocol for integration. In order for iKnode to be able to interact with a Wordpress blog, XMLRPC needs to be enabled in the site. You can do this by going to Settings > Writings, in the Remote Publishing Section check the XML-RPC check box.


Now we ready to create the iKnode App.

Creating the iKnode Application

The wrapper we created is in iKnode.Applications, so we don’t need to add any other assemblies. We just need to use the iKnode.Applications.Web namespace.

The signature of the method to add a new post is displayed below:

Code
1
2
3
4
5
6
7
8
9
10
/// <summary>
/// Posts a news Document into a wordpress blog.
/// </summary>
/// <param name="title">Post Title.</param>
/// <param name="content">Post Content.</param>
/// <param name="categories">Categories Array.</param>
/// <param name="keywords">Keywords.</param>
/// <param name="excerpt">Excerpt.</param>
/// <returns>Post Identifier if successful.</returns>
public string NewPost(string title, string content, string[] categories, string[] keywords, string excerpt)
Code
1
2
WordPressClient wp = new WordPressClient("http://my.domain.com/xmlrpc.php", "myUserName", "MyPassword");
wp.NewPost("Test Title", "Hello World!", new string[] {"Uncategorized"}, new string[]{}, String.Empty);

It is as simple as initializing the WordPressClient and then just passing the parameters to the NewPost method.

Here is the complete sample

Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using iKnode.Applications;
using iKnode.Applications.Web;

namespace Applications
{
  [Application]
  public class MyWordpressApp
  {
        public string HelloWorld()
        {
            WordPressClient wp = new WordPressClient("http://my.blog.com/xmlrpc.php", "myUserName", "myPassword");
            return wp.NewPost("Test Title", "Hello World!", new string[] {"Uncategorized"}, new string[]{}, String.Empty);
        }
  }
}

Just run this sample. Once it finishes it will return the blog post id and you should be able to see it in your Wordpress site.