Content by multiple categories
Is there a way to show content that belongs to multiple categories? We are currently able to show content from a single category based on the code that we found on this forum:
var content = App.WorkWith()
.ContentItems()
.Where(ci =>IList<Guid>)ci.GetValue(
"Category"
)).Contains(taxa.Id))
.Where(ci => ci.Status == ContentLifecycleStatus.Live);
Hello Ann,
You can use AND operator
sample
var cat1Id =
new
Guid(
"61FF245B-23C7-453F-8DE6-2FF8EC46E125"
);
var cat2Id
=
new
Guid(
"551491B6-A5B1-4B4F-B3A7-F1685C5E4DFF"
);
var news = App.WorkWith()
.NewsItems()
.Where(ni => ((IList<Guid>)ni.GetValue(
"Category"
)).Contains(cat1Id) && ((IList<Guid>)ni.GetValue(
"Category"
)).Contains(cat2Id
))
.Get();
Excuse me..... how did you defined ni?
I've got Telerik.Sitefinity.Model.DataExtensions but I'm not able to use it without doing Telerik.Sitefinity.Model.DataExtensions.GetValue(...)
Thanks
Hi,
GetValue is extension inside public static class DataExtensions, namespace Telerik.Sitefinity.Model
Regards,
Ivan Dimitrov
the Telerik team
Anybody having issues with this please check out:
http://www.sitefinity.com/devnet/forums/sitefinity-4-x/developing-with-sitefinity/newsitem-query.aspx
For some reason, the example provided as (List<Guid>) does not work. You have to use GetValue<List<Guid>>()