Using WordPressSharp To Publish A Post

January 26, 2015

development

This is a brief intro to using WordPressSharp to publish a post with C# via the WordPress XML-RPC API.

A few notes... the 'PostType' property of the Post class can be set to either "post" or "page" depending on which WordPress type you want to publish.

And the 'Status' property can be set to either "publish" or "draft" depending on whether you want to publish your new post/page right away or not.

In the future I'd like to make these enums or something extendable. But WordPress has them as strings so you can define new ones (ie Custom Post Types) on your own. Keep in mind this class is merely a simple example. In most cases you might want this in a service layer where you can inject the WordPressSiteConfig class as you need it.

Update: 8/11/2017 There have been a lot of questions about how to add tags and categories to a post since this example contains none. First off - the tag/category/custom taxonomy needs to exist first so you have to create it. Then attach it to the Terms[] collection on the post when creating it.

Here's an example: https://github.com/abrudtkuhl/WordPressSharp/issues/68#issuecomment-321923121 Also - the WordPressSharp nuget package has been updated to the latest and greatest.

Subscribe to my mailing list