Question

I am having trouble formatting a KQL statement which returns all Blog Posts from an entire site collection. Bonus points if I can filter by date posted, to only get newer Blog Posts. I am unsure if Blog posts would be STS_ListItems or not.

I have been trying to build one, but it has not been successful.

keywordQuery.QueryText = "spcontenttype:" + SPBuiltInContentTypeId.BlogPost.ToString();
Was it helpful?

Solution

Blog posts will always have a Content Type Id starting with 0x0110, so this query will show you all blog posts:

keywordQuery.QueryText = "ContentTypeId:0x0110*";

And this query will also let you filter by date - in this example, only display blog posts from 2016-01-01:

keywordQuery.QueryText = "ContentTypeId:0x0110* Created>=2016-01-01";

By default these queries will return you ALL blog posts, not just those in the site collection. To show all bog posts just for one specific site collection, you also need to add a Path filter with the URL of your site collection, like this:

keywordQuery.QueryText = "ContentTypeId:0x0110* Created>=2016-01-01 Path:http://example.com/sites/site1";
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top