More in this section

Forums / Developing with Sitefinity / FilterExpression Multiple tags

FilterExpression Multiple tags

2 posts, 0 answered
  1. Brendan
    Brendan avatar
    5 posts
    01 May 2008
    18 Feb 2009
    Link to this post
    I've seen the examples given on how to use the filterexpression with tags, for instance:

    Publication_Date <= "#now" AND Expiration_Date > "#now" AND Tag.Name = "mytag"

    I have this working well, but I'd like to be able to use the filterexpression on multiple tags, so that the items (news items in this case) returned by the filterexpression are all identified with each tag in the expression. I've tried using multiple "AND Tag.Name=" and introducing LIKE into the expression for tag.Name, but to no avail. Can this be done, and if so what is the proper syntax?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    19 Feb 2009
    Link to this post
    Hi Brendan,

    In this case filterexpression will not list the items that have been tagged. You should use the intersection approach.

    Here is a sample:

              string Tag1 = tag1; 
            string Tag2 = tag2; 
            NewsManager newsManager = new NewsManager("News"); 
            IList listOfAllNews = newsManager.Content.GetContent(0, 0, string.Empty, Tag1); 
            IList listOfAllNews1 = newsManager.Content.GetContent(0, 0, string.Empty, Tag2); 
            // here we are using intersection  
            List<IContent> intersection = new List<IContent>(); 
            foreach (IContent c1 in listOfAllNews) 
                foreach (IContent c2 in listOfAllNews1) 
                    if (c1.ID == c2.ID) 
                    // list the content titles here  
            foreach (IContent item in intersection) 
        #region properties 
        public string Tag1 
            get { return this.tag1; } 
            set { this.tag1 = value; } 
        public string Tag2 
            get { return this.tag2; } 
            set { this.tag2 = value; } 
        #endregion properties 
        #region private fileds 
        private string tag1; 
        private string tag2; 
        # endregion private fileds 

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered