1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Content by multiple categories

Content by multiple categories

5 posts, 0 answered
  1. Ann
    Ann avatar
    16 posts
    Registered:
    25 Aug 2010
    10 Sep 2010
    Link to this post
    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
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Sep 2010
    Link to this post
    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
  3. Paolo
    Paolo avatar
    147 posts
    Registered:
    11 Jun 2009
    27 Jan 2011
    Link to this post
    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
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Jan 2011
    Link to this post
    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
  5. Conrad Ehinger
    Conrad Ehinger avatar
    59 posts
    Registered:
    22 Sep 2009
    23 Aug 2011
    Link to this post
    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>>()
5 posts, 0 answered