Filtering by multiple tags - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Filtering by multiple tags

  • Filtering by multiple tags
  • I created a custom module with an MVC widget that I'm trying to filter the content by tags.  How do I filter by multiple tags?

    This works for a single tag:

    var myCollection = dmm.GetDataItems(iconType).Where(p => (p.Status == ContentLifecycleStatus.Live && p.Visible == true)).Where("Tags.Contains((" + SelectedTags[0] + "))")


    I tried a comma delimited string of SelectedTags but that did not work.  



  • Hi Tom, based on this documentation

    You should use something like that: 

    ((Category.Contains("Taxonomy ID") OR Category.Contains("Taxonomy ID"))
  • Thanks Victor, that isn't the exact syntax, but after much trial and error, I did find a magic combination using dynamic linq.

    var Tags = "Visible = true AND Status = Live AND (";

         foreach (Guid Tag in selectedTags)      


                 Tags += "Tags.Contains((" + Tag + ")) OR ";      


    var myCollection = dmm.GetDataItems(iconType).Where(Tags.Substring(0, Tags.Length-4) + ")")

    Couple notes...2 sets of parentheses are required for each Tags.Contains.  Tags cannot be a string value, it must be a var with guid value appended to it.  


    edit: changing my answer after finding a solution.