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

Forums / Developing with Sitefinity / Filtring Documents with multiple tags

Filtring Documents with multiple tags

2 posts, 1 answered
  1. Lucas
    Lucas avatar
    65 posts
    Registered:
    22 Mar 2010
    08 Jun 2010
    Link to this post
    Hi,

    For some reason, adding the following in CreateDataSource() doesn't work inside a DocumentList:
    // tags contains the Guids corresponding to the tags I want to display
    if
    (tags.Count > 0)
    {
     
        var filterTags = filter.GenerateCommaDelimitedString<Guid>(tags);
     
     
        var statement =
            new ContentFilterStatement("Tag.ID", filterTags , ContentFilter.Condition.In,
                                       ContentFilter.JoinType.And);
     
        filter.AddFilter(statement);
    }

    (this part of the filter  is ignored, I also check for categories but these are taken into account)

    Having a single Tag.Name works, though. It seems the filter is dropped because ParseTagFilter() expects a Tag.Name

    Is there a way to achieve this?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 Jun 2010
    Link to this post
    Hello Lucas,

    You need to use foreach and loop through each item from the "filterTags" and add a new filter. You have to get the ITag and its name by passing the ID from the filter. There is no overload in GetContent that allows you to filter by Tag.ID.

    foreach (Guid id in filterTags)
    {
        ITag tag = Manager.GetTag(id);
        if (tag != null)
        {
              var statement =
             new ContentFilterStatement("Tag.Name", tag.TagName,  ContentFilter.Condition.Equal,ContentFilter.JoinType.And));
             filter.AddFilter(statement);
        }
    }


    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.
    Answered
2 posts, 1 answered