Creating a new post in WordPress using the JoeBlogs library
A few people have recently been asking how the NewPost method works within JoeBlogs
First, you need to create an instance of Post.
Then, set the following properties:
dateCreated
Fairly self explanatory, but you should set this to today’s date (or whatever date you wish the post to be set as published)
title
The title of the post
description
The body of the post.
This can of course contain HTML
categories
This is a string array of categories to associate with the post
mt_keywords
Another string array, representing the tags for the post
Then, using your presumably already instantiated Wrapper class, you can call the NewPost method, which takes the above Post object as a parameter, and a boolean – indicating if the post is to be set as published. Note – if this is set to false, the post is set in draft mode.
Here’s some sample code:
//create a new post var post = new Post(); //since this is a struct, we can't have a constructor that does this! post.dateCreated=DateTime.Now; post.title="This is a title"; post.description="this is the body of the post. it <strong>could</strong> be html."; //create the post! wp.NewPost(post,true);
Hope this helps!
October 12th, 2009 at 9:49 pm
I added this demo code to revision #32613 on CodePlex:
http://joeblogs.codeplex.com/
October 20th, 2009 at 5:04 am
Hey Alex,
I love your plugin and wanted to thank you for putting it together
-Anonymous
October 22nd, 2009 at 9:11 pm
As with any early software version under development, bugs are found and fixed as part of the testing and development. ,
October 23rd, 2009 at 4:53 am
Exactly.
This project is open source – if people find bugs and would like to fix, please let me know and I will add you as a contributor on codeplex
October 27th, 2009 at 6:05 am
Thanks a million for sharing this info.
April 25th, 2010 at 11:54 am
Thanks for putting this together, the WP documentation is sparse!
Is there a way to set the slug, or to get it once the post is created? The postid is empty after I create the post.
July 18th, 2010 at 9:57 pm
It looks like a while since you’ve supported this library. I concur with Dave, is there any way to get the post’s ID or slug after posting?
July 18th, 2010 at 10:20 pm
Yeah, it’s been a while – I’m working on updating it at the moment though!
July 19th, 2010 at 5:46 pm
Awesome! I’ll look for the update. Also, mt_keywords doesn’t seem to have a definition in the post struct.
BTW, excellent library, thanks.