Skip to content

Instantly share code, notes, and snippets.

@plompd
Last active November 21, 2016 22:06
Show Gist options
  • Save plompd/5626202 to your computer and use it in GitHub Desktop.
Save plompd/5626202 to your computer and use it in GitHub Desktop.
Filter Dynamic Content Items by one or multiple categories
/// <summary>
/// Get an IQueryable result of Dynamic Content Items filtered by multiple categories
/// </summary>
/// <param name="categoryIds"></param>
/// <param name="dynamicType"></param>
/// <returns></returns>
private IQueryable<DynamicContent> GetItemsByCategories(Guid[] categoryIds, Type dynamicType) {
// Get the DynamicModule manager
var dynamicModuleManager = DynamicModuleManager.GetManager();
// Get an IQueryable result of dynamic content items filtered by multiple categories
var dynamicContentItems = dynamicModuleManager.GetDataItems(dynamicType).Where(
x => x.GetValue<TrackedList<Guid>>("Category").Any(t => categoryIds.Contains(t)) &&
x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
return dynamicContentItems;
}
/// <summary>
/// Get an IQueryable result of Dynamic Content Items filtered by one category
/// </summary>
/// <param name="categoryIds"></param>
/// <param name="dynamicType"></param>
/// <returns></returns>
private IQueryable<DynamicContent> GetItemsByCategory(Guid categoryId, Type dynamicType) {
// Get the DynamicModule manager
var dynamicModuleManager = DynamicModuleManager.GetManager();
// Get an IQueryable result of dynamic content items filtered by one category
var dynamicContentItems = dynamicModuleManager.GetDataItems(dynamicType).Where(
x => x.GetValue<TrackedList<Guid>>("Category").Contains(categoryId) &&
x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
return dynamicContentItems;
}
@farajoomla
Copy link

Hi, I am using some custom hierarchical list classifications to filter my events but in front-end, Sitefinity is only allowing me to use one classification at a time to filter the events. How can I use your code to enable multiple classification selection before filtering the events? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment