How to filter News by custom classification? - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

How to filter News by custom classification?

  • How to filter News by custom classification?
  • Hi Sandeep,

    There is a FilterExpression property in the lists definition of the control which you can use to filter the control by taxon, but you should know its ID.


    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  • Is there a way to filter News by custom classification?
  • Adding the code you posted to the filter expression of the NewsFrontEndList control causes an Object Reference error. Is there a special syntax for this type of filter?
    Filter Expression Used:
    Visible = true AND Status = Live AND Taxonomy.Contains("3707be29-9620-4aab-b7a7-6457a6dc3269") 
    Received Error
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Stack Trace:
    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.FindMethod(Type type, String methodName, Boolean staticAccess, Expression[] args, MethodBase& method) +58
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParseMemberAccess(Type type, Expression instance) +665
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParsePrimary() +51
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParseUnary() +114
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParseMultiplicative() +54
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParseAdditive() +59
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParseComparison() +54
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() +54
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParseLogicalOr() +54
       Telerik.Sitefinity.Data.Linq.Dynamic.ExpressionParser.ParseExpression() +27
       Telerik.Sitefinity.Data.Linq.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) +65

  • Hello Sandeep,

    What is the name of your custom taxonomy - "Taxonomy" or another one?

    Ivan Dimitrov
    the Telerik team
  • Ivan,

    My custom classification's name is not Taxonomy, it is 'PressRoomClassification'.
    I also tried the following filter expression and still getting the same error.
    Visible = true AND Status = Live AND PressRoomClassification.Contains("A9F2C13A-9472-4BF6-AB3D-19B2EF05B043")

  • Hey guys, this question has been sitting for a few days now. The project Sandeep is working on is coming close to deadline. Is there a functional way to filter by a custom Taxonomy?
  • Hi Sandeep,
    We currently don't support filtering for custom classifications.

    However here is the way you can do it:

    This gets a list of news items with the tag "one" that were live:

    private TaxonomyPropertyDescriptor GetPropertyDescriptor(Type itemType, ITaxon taxon)
         return TaxonomyManager.GetPropertyDescriptor(itemType, taxon);
     private IEnumerable GetItems(ITaxon taxon, ContentDataProviderBase contentProvider, Type itemType)
         TaxonomyPropertyDescriptor prop = GetPropertyDescriptor(itemType, taxon);
         int? totalCount = 0;
         var items = contentProvider.GetItemsByTaxon(taxon.Id, prop.MetaField.IsSingleTaxon, prop.Name, itemType, string.Empty, string.Empty, 0, 100, ref totalCount);
         return items;
     public void Button1_Click(object sender, EventArgs e)
         List<NewsItem> niL = new List<NewsItem>();
         TaxonomyManager taxManager = TaxonomyManager.GetManager();
         //Get the tag called "One"
         var taxon = taxManager.GetTaxa<FlatTaxon>().Where(t => t.Name == "One").Single();
         //I want the news items
         string itemTypeName = "Telerik.Sitefinity.News.Model.NewsItem";
         Type itemType = TypeResolutionService.ResolveType(itemTypeName);
         var manager = ManagerBase.GetMappedManager(itemType, "");
         ContentDataProviderBase contentProvider = manager.Provider as ContentDataProviderBase;
         var v = GetItems(taxon, contentProvider, itemType);
         //Load into strongly typed list
         foreach (NewsItem n in v)
         Response.Write(niL.Where(a => a.Status == ContentLifecycleStatus.Live).First());

    Kind regards,
    the Telerik team
  • To anyone that comes across this in the future, here is a function to handle getting items by custom classification.

    private static IList<T> GetItemsByTaxonomy<T>(ITaxon taxon, ContentDataProviderBase contentProvider)
                var prop = TaxonomyManager.GetPropertyDescriptor(typeof (T), taxon);
                    //GetPropertyDescriptor(typeof(T), taxon);
                int? totalCount = 0;
                    contentProvider.GetItemsByTaxon(taxon.Id, prop.MetaField.IsSingleTaxon, prop.Name, typeof (T),
                                                    string.Empty, string.Empty, 0, 100, ref totalCount).Cast<T>().ToList();


    var taxon = TaxonomyManager.GetManager().GetTaxa<FlatTaxon>().Where(t => t.Name == "CarrierHostedCall").SingleOrDefault();
    if (taxon != null)
            var evnts = GetItemsByTaxonomy<Event>(taxon, EventsManager.GetManager().Provider);
            foreach(Event evnt in events)
                do something....

  • I know this forum is a little old but for the sake of someone coming across this down the road I find that filtering new/events etc... by custom classification using filterexpression in the view works fine for me, such as
    Visible = true AND Status = Live AND CustomClassification.Contains("A9F2C13A-9472-4BF6-AB3D-19B2EF05B043")

    Is this something that was fixed in one of the releases because I see below you say it isn't supported.
  • Hello,

    The filter for custom classifications was not working and this was a known issue. A lot of fixes were made lately and this is the reason for your successful filtering. However, if you find any problems with it, feel free to contact us.

    Kind regards,
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  • What is now (SiteFinity v4.4) the recommended way to filter RealEstate items by complex criteria including custom classification?
  • Hi Dan,
    Not sure which is the recommended method of filtering custom classifications, but in 4.4 only this worked for me:

    var filterExpression = DefinitionsHelper.GetFilterExpression(masterDefinition);
    if (!String.IsNullOrEmpty(LocationFilter()))
        filterExpression += " AND Locations.Contains(\"" + LocationFilter() + "\")";

    where LocationFilter was returning a guid as a string. i haven't upgraded my current project to 5 yet so maybe it is working there.
  • I am on Sitefintiy 5.0.1, and when I tried

    Visible = true AND Status = Live AND Taxonomy.Contains("d004e36c-a186-47bd-a321-eb834f100162","9de21464-b26e-4945-8be4-fc8f2a0ed264")


    Visible = true AND Status = Live AND CustomClassification.Contains("d004e36c-a186-47bd-a321-eb834f100162","9de21464-b26e-4945-8be4-fc8f2a0ed264")

    Both were accepted; solution recompiled, but it will not be usable when tried to drag to be used.