Finding posts programmatically

Topics: ASP.NET 2.0
May 7, 2010 at 7:40 PM

I'm developing an extension that loads content from XML and creates a new post from it.  I need it to check for existing posts to avoid duplicates.  Is there any way to find a post by something other than GUID?  Or even a decent workaround to look up the GUID from some knowledge of the content?

Coordinator
May 7, 2010 at 10:49 PM

You can find post(s) by any piece of data.  The posts are exposed thru Post.Posts.  You can loop thru them and find the ones you're interested in.  For example:

foreach (Post post in Post.Posts)
{ 
	if (post.Title.IndexOf("test", StringComparison.OrdinalIgnoreCase) != -1)
		bool titleContainsTest = true;
	else if (post.Content.IndexOf("test", StringComparison.OrdinalIgnoreCase) != -1)
		bool bodyContainsTest = true;
}