Content by multiple categories

Posted by Community Admin on 03-Aug-2018 15:38

Content by multiple categories

All Replies

Posted by Community Admin on 10-Sep-2010 00:00

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);

We want to have the option of only displaying content that is contained in two or more specific categories.  For example selecting both the categories "Car Accessories" and "Truck Accessories" would display the accessories that both of these categories have in common, such as "Travel Mug."

Thanks in advance!
Ann

Posted by Community Admin on 10-Sep-2010 00:00

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();


Greetings,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 27-Jan-2011 00:00

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

Posted by Community Admin on 28-Jan-2011 00:00

Hi,

GetValue is extension inside public static class DataExtensions, namespace Telerik.Sitefinity.Model

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 23-Aug-2011 00:00

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>>()

This thread is closed