Orchard Query that filters by Content Type BlogPost and certain BlogId

asp.net-mvc, orchardcms

Solution

This would be a pretty simple filter to add within a module. Here is a bit of a hard-coded example that filters by id...

public class ContentIdFilter : IFilterProvider {
    private const int HardCodedId = 99;

    public ContentIdFilter() {            
        T = NullLocalizer.Instance;
    }

    public Localizer T { get; set; }

    public void Describe(DescribeFilterContext describe) {
        describe.For("Content", T("Content"), T("Content"))
            .Element("ContentId", T("Content Id"), T("Content w/ Id: " + HardCodedId.ToString()), 
            ApplyFilter, 
            DisplayFilter, 
            null);
    }

    public void ApplyFilter(dynamic context) {
        var query = (IHqlQuery)context.Query;
        context.Query = query.Where(x => x.ContentItem(), x => x.Eq("Id", HardCodedId));
    }

    public LocalizedString DisplayFilter(dynamic context) {
        return T("Content w/ Id: " + HardCodedId.ToString());
    }
}

There's a little more to it to make the Id number configurable, but this should put you on the right track.

Problem

I have a Orchard installation with two Blogs, one of them for Company News and the other for member publications. I want to create a widget that shows a subset of posts from the Company News blog. Is it possible in Orchard to create a Query that filters by the ContentType BlogPost and BlogId? I found a filter by Content Type, but I did not find a filter by BlogId.

Original source